When i try to read a JSON string like below it goes to endless loop.
<script language="javascript">
$(document).ready(function() {
$("#Button1").click(function() {
var json = "[{'City':'Lucknow','ID':'1'},{'City':'Mumbai','ID':'2'}]";
$.each(json, function() {
alert(this['City']);
});
});
</script>
Not sure what i am doing wrong? Please helpme out!
Use
jQuery.parseJSONto parse the JSON string with jQuery:The advantage of
jQuery.parseJSONis that it uses the native implementationJSON.parseof the browser if it supports it.Edit The problem that this is not working is probably that JSON does only allow strings to be declared with double quotes. The corresponding excerpt from the JSON specification:
So the following should work: