0

Possible Duplicate:
Parsing JSON using Json.net

I want to pull two values from this test string and save then as their own strings, the values I want our the first and second values in the following piece of text, the values for distance and duration, they are 178331, and 7761. The string I want to pull them from is as follows.

{
   "destination_addresses" : [ "1508-1520 38th Ave, Oakland, CA 94601, USA" ],
   "origin_addresses" : [ "800-828 Mountain Ranch Rd, San Andreas, CA 95249, USA" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "111 mi",
                  "value" : 178331
               },
               "duration" : {
                  "text" : "2 hours 9 mins",
                  "value" : 7761
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}
3
  • 10
    That smells like JSON, there are several good JSON parsers out there (both as part of the framework and third party). Just a thought. Commented Aug 22, 2011 at 13:57
  • 3
    Looks like the accepted answer here is what you need as well. Commented Aug 22, 2011 at 13:58
  • 3
    At least he didn't mention regex! Commented Aug 22, 2011 at 13:58

1 Answer 1

2

What you have here is definitely JSON and should be treated as such. To get the data you need to parse this. Try parsing using either the built in JavaScriptSerializer class or JSON.NET. (for more information, as pointed out by Shadow Wizard: Parsing JSON using Json.net)

Sign up to request clarification or add additional context in comments.

2 Comments

JSON.NET is 3rd party, I think you accidentally reversed them in your answer
@James You're right, I'll fix this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.