I want to parse json retrieved from url in jsp. 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.
<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"]}
no need of parsing(JSON.parse)..you can directly say
data.msgto get the required response as ajax responses can be directly in the form of JSON objects…if its not two dimensional
this should work for you. Tested it here.