0

I'm deserializing a json that has two segments for two types. One is an object (.Net object in the client application) and the other is a list of objects. So do I just grab the data from the JObject as a JToken and convert it into the type of .NET object I want? and how would I do that?

Currently I'm trying to do something like this:

JObject recipePageObject = JObject.Parse(await resp.Content.ReadAsStringAsync());
JToken recipeToken = recipePageObject["Recipe"]["data"].Children().

But I'm stuck on how to translate it into a C# object.

My JSON string is in the format:

[
  {
     "Recipe": {
        "data": [
           {
                fields
           }
       ],
  },
      "Ingredients": {
        "data": [
           {
                fields
           }
       ]
  }

]

Samuel Mungy
  • 447
  • 1
  • 6
  • 20
  • 1
    Share your json string to have better understanding. You can convert json string to C# classes and directly deserialize them. – Gaurang Dave Apr 16 '18 at 02:13
  • Possible duplicate of [How do I create a Dto in C# Asp.Net from a fairly complex Json Response](https://stackoverflow.com/questions/42708070/how-do-i-create-a-dto-in-c-sharp-asp-net-from-a-fairly-complex-json-response) – CodingYoshi Apr 16 '18 at 03:57

1 Answers1

0

From the newtonsoft help....

https://www.newtonsoft.com/json/help/html/SerializingJSONFragments.htm

once you have parsed your object. You can get to any token inside it and use token.ToObject<T>() on it to convert it to a C# object

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156