Get specifc value from JSon string using JSon.Net

Posted by dean nolan on Stack Overflow See other posts from Stack Overflow or by dean nolan
Published on 2010-03-30T18:11:15Z Indexed on 2010/03/30 18:13 UTC
Read the original article Hit count: 722

Filed under:
|

I am trying to get a value from a JSon formatted string. It was to get album info from a website called Freebase.

My result is like this:

{
  "a0": {
    "code": "/api/status/error",
    "messages": [
      {
        "code": "/api/status/error/mql/result",
        "info": {
          "count": 20,
          "result": [
            {
              "album": [
                {
                  "name": "Definitely Maybe",
                  "release_date": "1994-08-30"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Most Wanted Rock 1",
                  "release_date": null
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Alternative 90s",
                  "release_date": null
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Live Forever: Best of Britpop",
                  "release_date": "2003-03-03"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "The Best... In the World... Ever! Volume 5",
                  "release_date": "1997-03-31"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Live 4 Ever",
                  "release_date": "1998-06-29"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "De Afrekening, Volume 8",
                  "release_date": "1994"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Now That's What I Call Music! 33",
                  "release_date": null
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Q: Anthems",
                  "release_date": null
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "The Best Anthems... Ever! Volume 2",
                  "release_date": null
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "1995 Mercury Music Prize: Ten Albums of the Year",
                  "release_date": null
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Now That's What I Call Music! 1994",
                  "release_date": null
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Indie Top 20, Volume 21",
                  "release_date": "1995"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Dad Rocks!",
                  "release_date": "2006-06-05"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Untitled",
                  "release_date": null
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "The Greatest Hits of 1994",
                  "release_date": "1994-10"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Top of the Pops 2",
                  "release_date": "2000-03-27"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Q: Anthems (disc 1)",
                  "release_date": null
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Jamie Oliver's Cookin'",
                  "release_date": "2001"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            },
            {
              "album": [
                {
                  "name": "Killer Buzz",
                  "release_date": "2001"
                }
              ],
              "artist": "Oasis",
              "name": "Live Forever",
              "type": "/music/track"
            }
          ]
        },
        "message": "Unique query may have at most one result. Got 20",
        "path": "",
        "query": {
          "album": [
            {
              "name": null,
              "release_date": null,
              "sort": "release_date"
            }
          ],
          "artist": "Oasis",
          "error_inside": ".",
          "name": "Live Forever",
          "type": "/music/track"
        }
      }
    ]
  },
  "code": "/api/status/ok",
  "status": "200 OK",
  "transaction_id": "cache;cache04.p01.sjc1:8101;2010-03-30T18:04:20Z;0035"
}

I am looking to get the first album title, Definitely Maybe, from this list.

I have tried parsing the string like this:

JObject o = JObject.Parse(jsonString);
string album = (string)o[""];

But no matter what I have tried I don't know what to put in those quotes.

How would I get this specific value or be able to search for it?

Thanks

© Stack Overflow or respective owner

Related posts about JSON

Related posts about .NET