minijson使用,使用MiniJSON(Unity3D)解析嵌套的JSON

i'm very newbie with JSON so i'm having problems with nested JSON's.

I was searching two days without any luck, i saw a lot of examples of how to deserialize a nested JSON but my efforts failed so at last chance i'm here.

The thing i want to know is how i deserialize nested class with MiniJson, the JSONString is a facebook one, but i want to know the method for do it.

Here is an example of the JSONString i'm trying to deserialize.

{"data":

[{"user":{"name":"xxxxxxxxx1","id":"xxxxxxxxxx2"},"score":7,

"application":

{"name":"APPNAME","namespace":"APPNAMESPACE","id":"xxxxxxxxxx3"}}]}

Thanks in advance...

I tried with a lot of things this one is the last attempt i did, not a lot good but i was trying like a crazy to do it:

object dataObject;

object scoreObject;

var dict = Json.Deserialize(response.Text) as Dictionary;

Debug.Log(response.Text);

var scores = new List();

if(dict.TryGetValue ("data", out scoreObject)) {

Debug.Log("Hi");

scores = (string)(((Dictionary)scoreObject) ["score"]);

if(scores.Count > 0) {

var scoreDict = ((Dictionary)(scores[0]));

var score = new Dictionary();

score["score"] = (string)scoreDict["score"];

Debug.Log((string)scoreDict["score"]);

}

}

PD: Sorry if my question is very noob or if i have a lot of negatives but it's really my last chance to understand something, thanks again.

解决方案

Your problem lies in the fact that data contains an array and not an object, you need to get the first element of the data array and then get the value of score.

Something like this:

var dict = Json.Deserialize(response.Text) as Dictionary;

List scores = dict["data"] as List;

Dictionary scoreData = scores[0] as Dictionary;

object score = scoreData["score"];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值