Я пытаюсь получить значение id из следующего массива JSON.
[
{
"SaveValues": [
{
"id": 1,
"allposition": {
"x": -5.02046537399292,
"y": 4.489554405212402
},
"allrotation": {
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"allscale": {
"x": 1,
"y": 1
},
"linepos0": {
"x": 0,
"y": 0,
"z": 0
},
"linepos1": {
"x": 0,
"y": 0,
"z": 0
},
"movetype": 1
},
{
"id": 2,
"allposition": {
"x": -4.485479354858398,
"y": -4.903786659240723
},
"allrotation": {
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"allscale": {
"x": 1,
"y": 1
},
"linepos0": {
"x": 0,
"y": 0,
"z": 0
},
"linepos1": {
"x": 0,
"y": 0,
"z": 0
},
"movetype": 1
}
],
"NoteValues": [
{
"movenumber": 1,
"notemsg": "Attack"
}
]
},
{
"SaveValues": [
{
"id": 1,
"allposition": {
"x": -5.02046537399292,
"y": 4.489554405212402
},
"allrotation": {
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"allscale": {
"x": 1,
"y": 1
},
"linepos0": {
"x": 0,
"y": 0,
"z": 0
},
"linepos1": {
"x": 0,
"y": 0,
"z": 0
},
"movetype": 2
},
{
"id": 1,
"allposition": {
"x": 2.780655860900879,
"y": 4.399117469787598
},
"allrotation": {
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"allscale": {
"x": 1,
"y": 1
},
"linepos0": {
"x": 0,
"y": 0,
"z": 0
},
"linepos1": {
"x": 0,
"y": 0,
"z": 0
},
"movetype": 2
},
{
"id": 2,
"allposition": {
"x": -4.485479354858398,
"y": -4.903786659240723
},
"allrotation": {
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"allscale": {
"x": 1,
"y": 1
},
"linepos0": {
"x": 0,
"y": 0,
"z": 0
},
"linepos1": {
"x": 0,
"y": 0,
"z": 0
},
"movetype": 2
},
{
"id": 2,
"allposition": {
"x": 2.153193712234497,
"y": -4.7106828689575195
},
"allrotation": {
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"allscale": {
"x": 1,
"y": 1
},
"linepos0": {
"x": 0,
"y": 0,
"z": 0
},
"linepos1": {
"x": 0,
"y": 0,
"z": 0
},
"movetype": 2
}
],
"NoteValues": [
{
"movenumber": 2,
"notemsg": "Defend"
}
]
}
]
На самом деле я хочу показать только "id" из массива SaveValue [0], затем после нажатия кнопки затем«id» из массива SaveValue [1].
for (int i = 0;i<1;i++)
{
Debug.Log("Jnode values count " + JNode[i]["SaveValues"].Count);
for (int j = 0;j<JNode[i]["SaveValues"].Count;j++)
{
int id = JNode[i]["SaveValues"][j]["id"];
Debug.Log("id values --- " + id);
}
}
На самом деле я создаю файл JSON, используя следующий класс. Как получить его, используя тот же класс JSON, является проблемой. Как десериализовать его.
[System.Serializable]
public class PlayerHandler
{
public int id;
public Vector2 allposition;
public Quaternion allrotation;
public Vector2 allscale;
public Vector3 linepos0;
public Vector3 linepos1;
public int movetype;
public PlayerHandler(int ids,Vector2 allpos,Quaternion allrot,Vector2 allscal,Vector3 Line0,Vector3 Line1,int Moves)
{
this.id = ids;
this.allposition = allpos;
this.allrotation = allrot;
this.allscale = allscal;
this.linepos0 = Line0;
this.linepos1 = Line1;
this.movetype = Moves;
}
}
[System.Serializable]
public class PlayerMovement
{
public int movenumber;
public string notemsg;
public PlayerMovement(int Movenum,string Note)
{
this.movenumber = Movenum;
this.notemsg = Note;
}
}
Немного запутанно, я не понимаю, как зацикливаться и получать разные (настраиваемые) значения внутри JSON.