从JSON数组中获取特定值



我必须解析以下JSON:

{"type":"result","rid":"sample","data":[[{"artist":"Artist A","title":"Title A"}],false,0,1,0]}

我需要获取artisttitle的值。虽然无法弄清数据的格式,或者在JSON.NET或DYAMIC中解析它所需的内容。

我在动态中尝试的是

response = await client.GetStringAsync(uri);
dynamic data = JObject.Parse(response);
string currPlaying = data.data[0].title;

错误:'newtonsoft.json.linq.jarray'不包含'title'''

的定义

我在json.net中尝试的内容:

response = await client.GetStringAsync(uri);
List<OrionRootObject> playList2 = JsonConvert.DeserializeObject<List<OrionRootObject>>(response);
OrionRootObject firstItem2 = playList2.First();
currPlaying = firstItem2.data.First().artist;
...
        public class OrionRootObject
        {
            public string type { get; set; }
            public string rid { get; set; }
            public List<OrionPlaylist> data { get; set; }
        }
        public class OrionPlaylist
        {
            public string artist { get; set; }
            public string title { get; set; }
        }

错误:无法对当前的JSON对象(例如{" name":" value"}(进行类型

没事,得到它。

response = await client.GetStringAsync(uri);
dynamic data = JObject.Parse(response);
currPlaying = data.data[0][0].title + " - " + data.data[0][0].artist;

相关内容

  • 没有找到相关文章

最新更新