1

I got a response from a webservice as shown below

{
"header":    {
  "sourceId": "1002",
  "mndAction": "CREATE",
  "msgId": "msg10022",
  "errMsg": null,
  "txnStatusFlg": "1",
  "successMsg": "SUCCESS"
},
"response": {"responseString": "Required Data"}
}

I want to get the value of responseString from the above json data.

For the response

{"Status":"success","DocRepoId":225,"Details":"success",
"ErrorCode":"","responseString": "Required Data"}

I used the code

 var deserializer = new JavaScriptSerializer();
 var someObject = deserializer.Deserialize<Dictionary<string, string>>
 (response);     
 string responseString= someObject["responseString"].ToString();

to get the value of responseString but in this case its showing error. I'm looking for a solution without using json.net or anything similar. My project is on .net version 3.5.

Mr. Ambivert
  • 25
  • 1
  • 8

1 Answers1

0

Here it goes an example of what i told you in comment.

Using this classes:

    class Test
    {
        public Response Response { get; set; }
    }

    class Response
    {
        public string ResponseString { get; set; }
    }

You can get what you want with this code:

        JavaScriptSerializer s = new JavaScriptSerializer();

        string json = @"{
            ""header"":    {
                                ""sourceId"": ""1002"",
              ""mndAction"": ""CREATE"",
              ""msgId"": ""msg10022"",
              ""errMsg"": null,
              ""txnStatusFlg"": ""1"",
              ""successMsg"": ""SUCCESS""
                            },
            ""response"": { ""responseString"": ""Required Data""}
                        }";


        Test t = s.Deserialize<Test>(json);

        var responseString = t.Response.ResponseString;
bruno.almeida
  • 2,746
  • 1
  • 24
  • 32