i want to parse json retrieved from url in jsp. Can anyone please help? My url is giving response in json format and now i want to call it in my html page. My url is giving response as

{"status":1,"msg":"List of Rooms","id":["1","2","3"],"name":["php","Java","myroom4"]}

I am not able to understand what is going wrong. please help.

<script type="text/javascript" charset="utf-8">

    $.get('http:....', function(data, textStatus) {
        alert('Status is '+textStatus);
        alert('JSON data string is: '+data);

        var myJson = JSON.parse(data);
        var myJson = JSON.parse(textStatus);
        var myJsonObj = jsonParse(myJson);

        alert(myJsonObj.msg); 


        }, 'text');

</script>

My url is giving response as

{"status":1,"msg":"List of Rooms","id":["1","2","3"],"name":["php","Java","myroom4"]}
share|improve this question

29% accept rate
2  
Do you get an error ? What is it ? – Didier Ghys Feb 15 at 6:28
no i am not getting any error. actually i am not getting any response only. – SONAL KASLIWAL Feb 15 at 6:51
feedback

2 Answers

up vote 3 down vote accepted

no need of parsing(JSON.parse)..you can directly say data.msg to get the required response as ajax responses can be directly in the form of JSON objects...

if its not two dimensional

$.getJSON(
          "http....url",
          function(data){

              alert(data.msg);

              });

this should work for you. Tested it here.

share|improve this answer
can you please be a bit brief? please write the code if possible – SONAL KASLIWAL Feb 15 at 6:56
hope the edited answer works for u... – CodeJack Feb 15 at 7:41
:( no it still did not work – SONAL KASLIWAL Feb 15 at 8:46
any error or same message???? – CodeJack Feb 15 at 9:11
actually my page is not showing any response. – SONAL KASLIWAL Feb 15 at 9:26
show 11 more comments
feedback

Why not use the more appropriate .getJSON() method?

$.getJSON("http://chat.centerac.com/myapp.php?id=list_of_rooms", function(data) {
    alert(data.msg);
});
share|improve this answer
its still not working. can you please write the code? – SONAL KASLIWAL Feb 15 at 6:56
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.