2
{"status":1,"msg":"Success","details":{"123456789":{"id":"4029292","name":"ram"}}}

This is my string (I think json array not sure). I got this as response from webservice.

How do I get elements from this?

4
  • I think you need to add more details. Are you using jquery? Are you using ajax? Commented Sep 5, 2012 at 6:57
  • How do you plan to consume this web service? c#, javascript? Commented Sep 5, 2012 at 7:03
  • WebRequest request = WebRequest.Create("url"); postdata = "jxsdklgjskdgsdkgl..." bytedata = Encoding.UTF8.GetBytes(postdata); request.ContentLength = bytedata.Length; request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; Stream dataStream = request.GetRequestStream(); dataStream.Write(bytedata, 0, bytedata.Length); dataStream.Close(); WebResponse response = request.GetResponse(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); String resp = reader.ReadToEnd(); // reps=response string Commented Sep 5, 2012 at 7:15
  • i need to parse the elements in codebehind Commented Sep 5, 2012 at 7:16

3 Answers 3

4

If you are trying to parse it in C#, try using newtonsoft json.net for parsing json response.

It is simple and easy

Following are some references

Link1

Link2

Link3

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

Comments

2

Take a look at the Json.Net library.
You can use it to deserialize json in both c# and javascript.

Message deserializedProduct = JsonConvert.DeserializeObject<Message>(json);

The Message class would have to map to response you are getting.

Comments

1

Below is my code to append a json response to the listview.It may be a good example. Also try this (Javascript):

data.msg[key] or
data.msg.123456789.id

$.each(data.response, function(key, value) {
            html += '<li><a class=contact href="#" id="' + data.response[key].id + '" ><h1>' + data.response[key].label + '</h1><p>'+ data.response[key].customerName + '</p><p>' + data.response[key].phone + ', ' + data.response[key].email + '</p></a></li>';
            $('#ul_id').append($(html));
            html='';
            console.log('conatct');
            });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.