I have following jQuery/JS code
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$.getJSON("http://example/topics", {}, function(data){
console.log( data ); // display the JSON *data* in the web console
console.log( $.parseJSON(data) );
});
</script>
console.log(data) shows JSON data within firebug console (firefox add-on), but console.log( $.parseJSON(data) ) shows null.
what could be possible reason.
I need to convert JSON string into array.
Empty ValuesNull values and empty strings (“”) are valid JSON values, but the state of being undefined is not valid within JSON.
I assume because $.getJSON
already parsed the data. data
is Javascript object.
The
success
callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and parsed using the$.parseJSON()
method.
Of course we could say more if you show us the output, but normally, $.getJSON
already parses the response.
P.S.: I hope you use a proper URL in your real code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With