Loop JSON object RRS feed

  • Question

  • User-2021793694 posted


    I have below JSON data (it consists of thousand of record)

                 "name":"Name AA",
                 "item_Desc":"AA Desc"
             "name":"Name BB",
             "item_Desc":"BB Desc"

    And i need to insert it into a database with below format

    ItemID | Name       | Item_Desc
    20057  | Name AA    | AA Desc
    20060  | Name BB    | BB Desc

    This is what i have right now.

                StreamReader streamReader = new StreamReader(@"~\data\test-data.json");
                string text = streamReader.ReadToEnd();
                JavaScriptSerializer ser = new JavaScriptSerializer();
                var jObj = (JObject)JsonConvert.DeserializeObject(text);
                var result = jObj["items"].Select(item => new
                    name = item["20057"]["name"], //test with hardcoded item id
                    //TO DO
                foreach (var item in result)
                    //insert into database                

     I am having problem in getting the Item ID as it is a "key" not a "value". 

    I need your help to improve on the "TO DO" part so that I can add all the item details into a list.

    Sunday, October 13, 2013 5:17 PM


All replies