在Unity中的C#中使用LitJson [英] Working with LitJson in C# in Unity

查看:112
本文介绍了在Unity中的C#中使用LitJson的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一段代码从Java移植到C#,并且陷入了JSon解析的困境. 看看下面的Java代码

I am trying to port a piece of Code from Java to C# and I am stuck in JSon parsing. Have a look at the following Java Code

        mJsonObject = new JSONObject(str);
        Iterator<String> keys=mJsonObject.keys();
        while(keys.hasNext()){

            String key=keys.next();
            String value=mJsonObject.getString(key);

            mAdData.add(new AdData(key, new JSONObject(value)));


        }

我有一个已验证Json格式的字符串,并将其传递给JSONObject,并且一切在Java中都可以正常工作,但是现在在C#Unity中,我无法成功将其移植.我正在使用LitJson执行此任务,但我不知道它是如何工作的.我严重卡住,请帮忙. 谢谢

I had a string which has verified Json format and I passed it to JSONObject and every thing was finely working in Java, but now in C# Unity I am not able to port it successful. I am using LitJson to perform this task and I have no idea how this works. I am badly stuck please help. Thanks

推荐答案

JSONObject class返回ICollection<string>.您可以像此那样迭代ICollection .因此,将您的while循环更改为foreach,如下所示:

The keys method of the JSONObject class returns an ICollection<string>. You can iterate an ICollection like this. So I would change your while loop into a foreach, like this:

foreach (string key in keys) {
    //whatever
}

这篇关于在Unity中的C#中使用LitJson的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆