-
-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[using in unity] can't assign ‘xxx’ (type System.String) to type ListJson.JsonData #117
Comments
Hi, Which version of LitJSON are you using? 0.16.0? What type is Did a quick .NET Fiddle with above json just using generic types and 0.16.0, can you repro there? Executing this code // Serialize JSON to object
var fromJson = "[{\"BattleCfg\":\"10_03_001\",\"SceneName\":\"RoomBall\",\"Item1\":\"1\",\"Prev\":\"0\",\"Item2\":\"2\",\"Next\":\"2\",\"Hp\":\"8\",\"Item3\":\"3\",\"Id\":\"1\",\"Name\":\"01\"}]";
var fromObject = LitJson.JsonMapper.ToObject<List<Dictionary<string, string>>>(fromJson);
foreach(var dictionary in fromObject)
{
foreach(var kv in dictionary)
{
Console.WriteLine(kv);
}
} outputs
So it looks like it at least can parse example json. Also did a test .NET Fiddle using a defined class public class Config
{
public string BattleCfg { get; set; }
public string SceneName { get; set; }
public string Item1 { get; set; }
public string Prev { get; set; }
public string Item2 { get; set; }
public string Next { get; set; }
public string Hp { get; set; }
public string Item3 { get; set; }
public string Id { get; set; }
public string Name { get; set; }
public override string ToString()
{
return string.Format(
"BattleCfg: {0}, SceneName: {1}, Item1: {2}, Prev: {3}, Item2: {4}, Next: {5}, Hp: {6}, Item3; {7}, Id: {8}, Name: {9}",
BattleCfg,
SceneName,
Item1,
Prev,
Item2,
Next,
Hp,
Item3,
Id,
Name
);
}
} and code // Serialize JSON to object
var fromJson = "[{\"BattleCfg\":\"10_03_001\",\"SceneName\":\"RoomBall\",\"Item1\":\"1\",\"Prev\":\"0\",\"Item2\":\"2\",\"Next\":\"2\",\"Hp\":\"8\",\"Item3\":\"3\",\"Id\":\"1\",\"Name\":\"01\"}]";
var fromObject = LitJson.JsonMapper.ToObject<Config[]>(fromJson);
foreach(var config in fromObject)
{
Console.WriteLine(config);
} outputted
So unfortunately not able to reproduce your error. |
sorry for my unclear description. |
it's quite a strange problem when I build my game to iOS platform and using
JsonMapper.ToObject<List<JsonData>>("some json string")
to parse object array json string.json string is "[{"BattleCfg":"10_03_001","SceneName":"RoomBall","Item1":"1","Prev":"0","Item2":"2","Next":"2","Hp":"8","Item3":"3","Id":"1","Name":"01"}]".
however, this codes works fine in unity editor...
The text was updated successfully, but these errors were encountered: