none
Parse Json Jtoken?? RRS feed

  • Question

  • I am struggle to parse the JToken. I am trying to grab the property and value.

    For example {"_modelNumber":false} I am trying to iterate through the list below and grab the value "_modelNumber" and "false" data in the below foreach added to my datatable. How would i parse correctly??

      dynamic eolResult = JsonConvert.SerializeObject(pagevm._eolmodel);

                JObject o = JObject.Parse(eolResult);

                IEnumerable<JToken> results = o.Children();

                foreach (JToken tempToken in results)
                {
                    
                    _eolTable.Rows.Add(tempToken);
                }

    


    pianoboyCoder

    Friday, January 19, 2018 4:19 AM

Answers

  • Hello pianoboyCoder,

    Just convert the JToken instance to JObject and access the key, value property.

     foreach (var tempToken in results)
                {
                    JObject obj = JObject.Parse("{" + tempToken.ToString()+"}");
                    foreach (var pair in obj)
                    {
                        Console.WriteLine(pair.Key + "," + pair.Value);
                    }
                }

    Did you solve issues on your previous post? It would be nice if you could mark the helpful reply as answer.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 19, 2018 11:03 AM
    Moderator

All replies

  • Hello pianoboyCoder,

    Just convert the JToken instance to JObject and access the key, value property.

     foreach (var tempToken in results)
                {
                    JObject obj = JObject.Parse("{" + tempToken.ToString()+"}");
                    foreach (var pair in obj)
                    {
                        Console.WriteLine(pair.Key + "," + pair.Value);
                    }
                }

    Did you solve issues on your previous post? It would be nice if you could mark the helpful reply as answer.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 19, 2018 11:03 AM
    Moderator
  • Hello pianoboyCoder,

    Is there any update or any other assistance I could provide? You could mark the helpful reply as answer if the issue has been solved. And if you have any concerns, please do not hesitate to let us know.

    Thank you for your understanding and cooperation.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, January 28, 2018 1:20 PM
    Moderator
  • Thank for this answer

    pianoboyCoder

    Monday, January 29, 2018 7:24 PM