Open Josk opened 8 years ago
an empty array is not the problem :)
NOTE: no exception catcher ;)
start.cs
using UnityEngine;
using System.IO;
using Newtonsoft.Json;
public class start : MonoBehaviour {
// Use this for initialization
void Start () {
Data data = JsonConvert.DeserializeObject<Data>(File.ReadAllText("./data.json").ToString());
UnityEngine.Debug.Log(data.status);
UnityEngine.Debug.Log(data.errorCode);
UnityEngine.Debug.Log(data.message);
UnityEngine.Debug.Log(data.fullErrorCode);
UnityEngine.Debug.Log(data.date);
}
}
Data.cs
using Newtonsoft.Json;
using System.Collections.Generic;
public class Data {
[JsonProperty(PropertyName = "status", Required = Required.Always)]
public int status;
[JsonProperty(PropertyName = "errorCode", Required = Required.Always)]
public List<int> errorCode;
[JsonProperty(PropertyName = "message", Required = Required.Always)]
public string message;
[JsonProperty(PropertyName = "fullErrorCode", Required = Required.Always)]
public int[] fullErrorCode;
[JsonProperty(PropertyName = "date", Required = Required.Always)]
public string date;
}
data.json
{
"status": 1,
"errorCode": [],
"message": "aircraft.listComplete",
"fullErrorCode": [],
"date": "2016-08-19 14:39:29.000000"
}
Due to lack of information i cant tell you where the problem is.
I'm not sure there is a problem or not because your start.cs works well under UnityEditor writing following output.
1
System.Collections.Generic.List`1[System.Int32]
aircraft.listComplete
System.Int32[]
2016-08-19 14:39:29.000000
If there is an error around this code, please let me know your environment :smile:
I should write more clear ;D With my code there shouldnt be an error. It was just a simple code, to show how he can parse his json. I think he has problems in his code, but didnt post it.
@IceflowRE Oh I missed it! Good explanation :+1:
@Josk From callstack, I suspect that a type of the field errorCode
of your class may be int or something scalar not array and it causes a parse error because scalar field cannot consume array at all.
Hi, We have a problem with your package. Our json looks like that:
When parsing, the code throw an exception:
How can I solve it?