-1

How can we parse this simple json using proper class & member variables

{
"item": [
    {
        "id": 12,
        "name": "Johnny"
    },

    {   "id":13,
        "name":"mohit"
    }
        ]
 }
Mohit Verma
  • 1,620
  • 2
  • 20
  • 30

1 Answers1

0

obviously u can use the Newtonsoft.Json(Json.NET) and call a method return with a anonymous type. like this:

                var anType = new
                {
                    multiResult = new
                    {
                        results = new[]
                        {
                          new 
                          {
                            description = string.Empty,
                            title = string.Empty,
                            picUrl = string.Empty,
                            totalTime = 0,
                            outerPlayerUrl = string.Empty,
                            picChoiceUrl = new string[] { "", "" }
                          }
                        }
                    }
                };

                //get info from JsonString
                var tudou = JsonConvert.DeserializeAnonymousType(jsonString, anType);

                return VideoDetail.CreateSimpleInstance(DateTime.Now,
                    tudou.multiResult.results[0].title,
                    tudou.multiResult.results[0].description,
                    tudou.multiResult.results[0].picUrl,
                    tudou.multiResult.results[0].outerPlayerUrl);
            }
Scott 混合理论
  • 2,263
  • 8
  • 34
  • 59