C# Unity MiniJSON:无法反序列化WWW响应
我正在发送一个WWW请求并获得JSON中正确的txt响应,但我不确定将JSON字符串反序列化到字典中有什么错。代码如下:C# Unity MiniJSON:无法反序列化WWW响应,c#,json,unity3d,C#,Json,Unity3d,我正在发送一个WWW请求并获得JSON中正确的txt响应,但我不确定将JSON字符串反序列化到字典中有什么错。代码如下: IEnumerator requestScores(int level) { WWW jsonScores = new WWW(requestScoresURL + level); yield return jsonScores; //Wait for download to complete float elapsedTime = 0.0f;
IEnumerator requestScores(int level)
{
WWW jsonScores = new WWW(requestScoresURL + level);
yield return jsonScores; //Wait for download to complete
float elapsedTime = 0.0f;
while (!jsonScores.isDone)
{
elapsedTime += Time.deltaTime;
if (elapsedTime >= 10.0f) break;
yield return null;
}
if (!jsonScores.isDone || !string.IsNullOrEmpty(jsonScores.error))
{
Debug.LogError(string.Format("Fail Whale!\n{0}", jsonScores.error));
yield break;
}
string response = jsonScores.text;
Debug.Log(elapsedTime + " : " + response);
// Here "search" gets null value
Dictionary<string, object> search = Json.Deserialize(response) as Dictionary<string, object>;
}
就我所知,jsonScores.txt检索正确,但字典搜索结果为空,我做错了什么
提前谢谢 好的,我发现了其中的错误,因为我得到了多行,需要反序列化到字典列表中,而不是单个字典 这是有效的代码:
List <Dictionary<string, object>> list;
list = Json.Deserialize(response) as List<Dictionary<string, object>>;
foreach (Dictionary<string, object> row in list)
{
// Do whatever with row
}