Unity中从网络获取JSON

参考地址

http://www.360doc.com/content/13/0117/11/10941785_260686840.shtml

将LitJson.dll放在assert下的plugins里然后如下操作

    void Start()
    {

        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            print("Network disconnected;");

        }
        else
        {
            StartCoroutine(GetPhotos());
        }
        
    }

    // Update is called once per frame  
    IEnumerator GetPhotos()
    {
        WWWForm form = new WWWForm();
        form.AddField("key", "896d6bbceafa4cd4b9cf22cee7a0e7cc");
        form.AddField("info","天气");
        WWW w = new WWW("http://www.tuling123.com/openapi/api", form);
        while (!w.isDone) { yield return new WaitForEndOfFrame(); }
        Debug.Log(w.text);
        JsonData jd = JsonMapper.ToObject(w.text);
        Debug.Log("text=" + jd["text"]);
        

    }


你可能感兴趣的:(unity)