为什么JSON在解析为JObject时返回null / blank结果? C#

时间:2017-10-04 08:45:15

标签: c# json xamarin xamarin.forms

我在从网址收集JSON时遇到了一些麻烦。我成功地将JSON读作字符串异步,但是当我尝试解析为JObject时,它返回null / blank结果。

JSON看起来像这样:

[{"name":"Name","desc":"Desc","id":1}, {"name":"Name","desc":"Desc","id":2}]

以下是代码:

    static public async Task<JObject> getData()
    {
            var httpClientRequest = new HttpClient();
            var result = await httpClientRequest.GetAsync("url");
            var resultString = await result.Content.ReadAsStringAsync();

            System.Diagnostics.Debug.WriteLine(resultString); //returns the json as a string

            var jsonResult = JObject.Parse(resultString);
            System.Diagnostics.Debug.WriteLine(jsonResult); //returns null/blank result
            return jsonResult;
    }

知道我做错了吗?

1 个答案:

答案 0 :(得分:0)

试试这个

var jsonResult = JArray.Parse(resultString);