c# - Newtonsoft JSON反序列化

时间:2016-09-27 01:13:49

标签: c# json datagridview

我遇到问题D:

我有一个JSON字符串,如下所示,并希望反序列化它:

[
      {
        "id": 37547411,
        "user_id": 116082,
        "identifier": "quest_stage1",
        "status": 1,
        "ts_complete": 0,
        "used_resources": 0,
        "rewards": "{\"coins\":14,\"xp\":213,\"honor\":0,\"premium\":0,\"statPoints\":0,\"item\":19628919}"
      },
      {
        "id": 37547416,
        "user_id": 116082,
        "identifier": "quest_stage2",
        "status": 1,
        "ts_complete": 0,
        "used_resources": 0,
        "rewards": "{\"coins\":6,\"xp\":600,\"honor\":0,\"premium\":0,\"statPoints\":0,\"item\":0}"
      }
    ]

我的代码:

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

 string json = responseString;

 JObject obj = JObject.Parse(json);

JToken teste = obj["data"]["quests"];

var result = JsonConvert.DeserializeObject<List<JsonResult>>(teste.ToString());

dataGridView1.DataSource = result;

my classe:

 public class JsonResult
    {
        public int id { get; set; }

        public int status { get; set; }

        public rewards rewards { get; set; }
    }


        public class rewards
        {
            public int coins { get; set; }
            public int xp { get; set; }
        }

我需要获取值coins和xp并将其放入datagridview

例如:
 example image

但我收到以下错误:

An unhandled exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll

Additional information: Error converting value "{"coins":14,"xp":213,"honor":0,"premium":0,"statPoints":0,"item":19628919}"]

我不知道该怎么做,我已经尝试过在互联网上找到的各种方法,但没有一种方法可行,我对它不是很好= /

我做错了什么?

0 个答案:

没有答案