Simple example for parseJSON function

Following is a simple sample app which parse a JSON string to a jQuery object and access a value in the JSON string.

    <script src="
http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var str = "[{\"CityName\":\"Colombo\",\"CityID\":1,\"ZipCodeID\":1,\"ZipCode\":1098},
        var test = jQuery.parseJSON(str);
        for (var i = 0; i < test.length; i++)
            alert(test[i].CityName); //Here, this will alert the City name in the JSON string

No comments: