{
"error": 0,
"msg": "排行数据获取成功",
"user_id": "88867256",
"ranktype": 1,
"rank": {
"90001": {
"nickname": "1",
"headicon": "",
"score": "9447",
"rankno": 1
}
}
}
JsonData jsonData = JsonMapper.ToObject(json); //json是上面的Json字符串
int error = (int)jsonData["error"];
JsonData jsonUserList = jsonData["rank"];
IDictionary dict = jsonUserList as IDictionary;
foreach (string key in dict.Keys)
{
ScoreRankUserInfo userInfo = new ScoreRankUserInfo();
JsonData data = dict[key] as JsonData;
Debug.Log(key);
Debug.Log(data["score"]);
Debug.Log(data["rankno"]);
Debug.Log(data["nickname"]);
Debug.Log(data["headicon"]);
}
注:若要判断 key 存不存在的话就这么写
不可写成
data["headicon"] != null 否则会报错