0

firstly thank you in advance I am having a lot of trouble with this one.

I am calling an API which sends back JSON in a really bad format. There seems to be arrays within arrays. How can I convert this into JSON objects so that the string is the @id and the value is "$"

{"cake-response-list": {
"@error": "EndOfResults",
"@throttle": "712",
"@total-cakes": "712",
"cake-responses": {
  "cake.model": [
    {
      "@mh": "0x1111111",
      "ns1.attribute": [
        {
          "@id": "0x22222",
          "$": "ChocGateux"
        },
        {
          "@id": "0x33333",
          "$": "ChocMud"
        }
      ]
    },
    {
      "@mh": "0x4444444",
      "ns1.attribute": [
        {
          "@id": "0x55555",
          "$": "VanillaSponge"
        },
        {
          "@id": "0x66666",
          "$": "RaspberryCheesecake"
        }
      ]
    },
    {
      "@mh": "0x7777777",
      "ns1.attribute": [
        {
          "@id": "0x88888",
          "$": "ChocEclair"
        },
        {
          "@id": "0x99999",
          "$": "StrawCheesecake"
         }
      ]
    }
  ]
}

} }

James Fraser
  • 15
  • 1
  • 6

1 Answers1

0

You can do a class similar to your JSON and then deserialize your JSON to it. And then work with it as with simple object.

Some articles that can be useful for you:

http://www.newtonsoft.com/json/help/html/SerializingJSON.htm

Deserializing JSON to .NET object using Newtonsoft (or LINQ to JSON maybe?)

Community
  • 1
  • 1
Oleh Udovytskyi
  • 300
  • 1
  • 2
  • 10