I would like to extract the JSON array inside the JSON string. But I am not able to figure out how to get it working. Please refer the code below:
/* I would like to get this working */
var all_barcodes = '{"VAM12345":{"colour":"red","size":"32"},"VAM456789":{"color":"red","size":"42"}}';
var print = $.parseJSON(all_barcodes); // this fails and hence the below loop won't run
$.each( print, function( key, value ) {
var color = value['color'];
var design = value['size'];
alert(color); alert(size)
});
/* This works well */
var test_string = '{"VAM12345":"test1","VAM456789":"test2"}';
var print_test = $.parseJSON(test_string);
$.each( print_test, function( key, value ) {
alert(key);
alert(value);
});
Edit 1: Sorry guys, there was a small typo..Since, I simplified the code from my original code. Please see the refined one ..sorry for the trouble.
Thanks!
size... That's probably all that is wrong...