在unity3d中使用LitJson

gre*_*reg 5 c# json unity-game-engine litjson

2个问题.

1)在Javascript中编写脚本时是否可以按原样使用LitJson库?这是一个关于能够在javascript源代码中使用c#source的一般问题.

2)我是c#dev的新手.我似乎无法让LitJson启动并运行.以下代码抛出此错误:An object reference is required to access non-static memberLitJson.JsonReader.Read()'`

using UnityEngine;
using System.Collections;

public class Loadr : MonoBehaviour {
string url= "http://developer.echonest.com/api/v4/artist/images?api_key=N6E4NIOVYMTHNDM8J&id=ARH6W4X1187B99274F&format=json&results=1&start=0&license=unknown";
void  Start (){
    WWW www = new WWW(url);
    print(www.text);
    Object a = LitJson.JsonReader.Read(www.text);
    print(a.response.status);

    }

}
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

Cal*_*vin 5

我在Unity3D中经历过一堆Json库.我发现的唯一一个没有奇怪的序列化/反序列化怪癖,并且在iOS,WebPlayer和Editor中一致地工作是JsonFX JsonSerializer 1.4.

也就是说,我认为你的问题是你必须先实例化一个JsonReader才能使用它的方法.

像这样的东西可能会起作用:

var reader = new LitJson.JsonReader();
Object a = reader.Read(www.text);
Run Code Online (Sandbox Code Playgroud)

编辑:

哎呀,我跳过你的部分问题.您应该能够使用UnityScript中的任何托管程序集,就像使用C#一样.using您可以使用而不是包含名称空间import.之后代码几乎与C#版本相同,除了UnityScript定义类型的方式(var blah : Type = YadaYada();)