c# - 我如何在 unity3d 中使用 minijson 打印键和值

标签 c# json unity3d monodevelop

我正在使用 minijson 从 unity3d 中的 json 中获取值

响应是

{"existing":[{"LastUpdated":"7\/9\/2013 4:03:57 AM","LetterSpeed":100,"Letters":"SP","NumRandom":5,"Reward":10,"ShowWordDesc":false,"ShowWordHint":false,"Sort_ID":5,"WN_Level_ID":34,"WN_Word_ID":95,"WordDesc":"","WordHint":"","zError":null},{"LastUpdated":"7\/9\/2013 4:03:57 AM","LetterSpeed":100,"Letters":"aún","NumRandom":2,"Reward":10,"ShowWordDesc":true,"ShowWordHint":false,"Sort_ID":10,"WN_Level_ID":34,"WN_Word_ID":83,"WordDesc":"still","WordHint":"","zError":null},{"LastUpdated":"7\/9\/2013 4:03:58 AM","LetterSpeed":200,"Letters":"tanto","NumRandom":3,"Reward":10,"ShowWordDesc":true,"ShowWordHint":false,"Sort_ID":20,"WN_Level_ID":34,"WN_Word_ID":84,"WordDesc":"so","WordHint":"","zError":null}]}

我使用的代码是

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using MiniJSON;

在函数中

string response = www.text; 
Debug.Log(response);            
IDictionary search = (IDictionary) Json.Deserialize(response);
IList tweets = (IList) search["existing"];      
foreach (IDictionary tweet in tweets) {
    Debug.Log(tweet["LastUpdated"]);                
} 

如果我不知道键名,如何保存键和值?

最佳答案

不完全确定您要在此处输出什么,但如果我猜测您想要执行以下操作:

string response = www.text; 

Debug.Log(response); 

IDictionary search = (IDictionary) Json.Deserialize(response);

IList tweets = (IList) search["existing"];  

foreach (IDictionary tweet in tweets) {
    Debug.Log("Tweet details:");
    foreach( KeyValuePair<string, string> tweetData in tweet )  {
        Debug.Log("Key = " + tweetData.Key.ToString() +
                  " Value = " + tweetData.Value.ToString());
    }            
}

关于c# - 我如何在 unity3d 中使用 minijson 打印键和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18223700/

相关文章:

c# - 当页面向后导航到带有 MapControl 的页面时,UAP 应用程序崩溃

c# - DateTime 转换为 Unix Epoch 添加 Phantom Hour

c# - 是否可以 StreamWrite DataList 结果来制作 HTML 文件? (ASP.NET)

json - 如何向 Laravel 分页 json 响应添加自定义属性

c# - Unity 3d 启用鼠标指针作为事件触发器的指针进入/退出

c# - 在Unity中,Unity是如何神奇地调用all "Interfaces"的呢?

c# - 创建具有相同C#源构建的完整.net,PCL和dotnet核心程序集的单个源项目?

c# - 如何在Javascript中处理ObjectId,无法解析它

javascript - 使用 JavaScript 从 Json 中获取键和值对

c# - WWW POST 给我内部服务器错误