Я искал, чтобы преобразовать элементы из двух списков, чтобы сформировать данные JSON. Когда я проверял JSON, он показывает ошибку. Код указан ниже
public struct ListContainer
{
public List<PlayerHandler> SaveValues;
public List<PlayerMovement> NoteValues;
public ListContainer(List<PlayerHandler> _saveVal,List<PlayerMovement> _noteVal)
{
SaveValues = _saveVal;
NoteValues = _noteVal;
}
}
//--Adding Two list into the container
ListContainer container = new ListContainer(getAlldata,playerNotes);
//--Adding data in container into List<string> jsonstring
jsonstring.Add(JsonUtility.ToJson(container));
Позже я сохраняю вышеуказанный список (CustomClass) jsonstring в файл JSON. Ниже приведена кодировка для сохранения его в постоянном пути.
public void Save()
{
//--Get Text typed in the input box
savedName = saveName.text;
//--Combing list of string into a single string
string jsons = string.Join(",", jsonstring);
//Writing into a JSON file in the persistent path
using (FileStream fs = new FileStream(Application.persistentDataPath + "/" + savedName+".json" , FileMode.Create))
{
BinaryWriter filewriter = new BinaryWriter(fs);
filewriter.Write(jsons);
fs.Close();
}
saveButtonShow.SetActive(false);
}
Когда я проверяю файл json по пути и пытаюсь проверить его,показывает ошибку. JSON, приведенный ниже.
{"SaveValues":[{"id":1,"allposition":{"x":-2.383237361907959,"y":-5.711871147155762},
"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},
"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},
"linepos1":{"x":0.0,"y":0.0,"z":0.0},
"movetype":1},{"id":2,"allposition":{"x":-4.0806732177734379,"y":5.998472213745117},
"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},
"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":1}],
"NoteValues":[{"movenumber":1,"notemsg":"First Move"}]},{"SaveValues":[{"id":1,"allposition":{"x":-2.383237361907959,"y":-5.711871147155762},
"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},
"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},
"linepos1":{"x":0.0,"y":0.0,"z":0.0},
"movetype":2},{"id":1,"allposition":{"x":4.558084964752197,"y":-5.517238140106201},
"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},
"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":2},
{"id":2,"allposition":{"x":-4.0806732177734379,"y":5.998472213745117},
"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},
"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":2},
{"id":2,"allposition":{"x":4.3838324546813969,"y":4.650305271148682},
"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},
"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":2}],
"NoteValues":[{"movenumber":2,"notemsg":"Second Move"}]}
Отображаемая ошибка:
Error: Parse error on line 61:
...: "First Move" }]}, { "SaveValues": [
---------------------^
Expecting 'EOF', got ','