Litjson 解析接口数据出现: JsonException: Invalid character '' in input string

    /// <summary>
    /// 5.3.6f1 加载数据
    /// </summary>
    /// <returns></returns>
    IEnumerator ReadData()
    {
        WWW www = new WWW("http://127.0.0.1:12307/broadcast?type=refreshFileList");
        yield return www;
        Debug.Log(www.text);
        LitJson.JsonData data = LitJson.JsonMapper.ToObject(System.Text.Encoding.UTF8.GetString(www.bytes, 3, www.bytes.Length - 3));
        Debug.Log(data["state"]);
        for (var i = 0; i < data["data"].Count; i++)
        {
            Debug.Log(data["data"][i].ToString());
        }
    }
    /// <summary>
    /// 2019.4.0f1 加载数据
    /// </summary>
    /// <returns></returns>
    IEnumerator ReadData()
    {
        string url = "http://127.0.0.1:12307/broadcast?type=refreshFileList";
        var req = UnityWebRequest.Get(url);
        yield return req.SendWebRequest();
        var text = req.downloadHandler.text;
        Debug.Log(text);
        LitJson.JsonData data = LitJson.JsonMapper.ToObject(System.Text.Encoding.UTF8.GetString(req.downloadHandler.data, 3, req.downloadHandler.data.Length - 3));
        Debug.Log(data["state"]);

    }
接口中返回的JSON数据:
{
"state":"200", "data":[ "D:\\广播音频\\Stream(2, 44.1k).wav", "D:\\广播音频\\Test1.wav", "D:\\广播音频\\播放.mp3" ] }

 

posted @ 2021-04-30 10:26  叶图大师  阅读(1457)  评论(0编辑  收藏  举报