0

I have this JSON string:

string ab="{\"1\":{\"oid\":\"2892\",\"order\":\"SD1427999310502\"},\"all\":1,\"time\":\"2015-02-02 10:37:55\"}";

How can I get the oid and order value?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
silex
  • 3
  • 2
  • 2
    I would start with looking at these questions: [`[c#] parse json`](http://stackoverflow.com/search?q=%5Bc%23%5D+parse+json) – Felix Kling Feb 03 '15 at 04:56
  • See http://stackoverflow.com/questions/2859753/what-is-the-simplest-c-sharp-function-to-parse-a-json-string-into-an-object – abatishchev Feb 03 '15 at 04:59
  • It's always a good idea to show what you've tried and what the results have been obtained. Check out the guide [here](http://stackoverflow.com/help/how-to-ask) to asking a good question on stackoverflow. – d3noob Feb 03 '15 at 05:00

1 Answers1

0

Include Newtonsoft.Json external DLL in your project references and use the below code.

string json_string = "{\"1\":{\"oid\":\"2892\",\"order\":\"SD1427999310502\"},
                      \"all\":1,\"time\":\"2015-02-02 10:37:55\"}";

JObject outer_object = JObject.Parse(json_string);
JObject inner_object = (JObject)outer_object["1"];
string oid_value = inner_object["oid"].ToString();
string order_value = inner_object["order"].ToString();
icedwater
  • 4,701
  • 3
  • 35
  • 50
Pruthviraj
  • 560
  • 6
  • 23
  • if there are more then 1 outer object. then how i will get all outer object and use them in for each loop to get all inner object values? – silex Feb 06 '15 at 11:14
  • example - string json_string = "{\"1\":{\"oid\":\"2892\",\"order\":\"SD1427999310502\"},"2":{\"oid\":\"3465\",\"orde\r":\"ebay311115155283-94587\"},"3":{\"oid\":\"3465\",\"orde\r":\"ebay311115155283-94587\"}, \"all\":1,\"time\":\"2015-02-02 10:37:55\"}"; – silex Feb 06 '15 at 11:17