简体   繁体   中英

JQuery, need to split stringify json string into array

I have a string in JSON format. I want to split all the values into array.

 [{ "sno": "1", "code": "bp150mb", "quantity": null, "name": "mudguard", "company": "bajaj", "vehicle": "pulsar", "brand": "1", "image": "N/A", "color": "Black", "price": "0" }, { "sno": "7", "code": "P", "quantity": "5", "name": "", "company": null, "vehicle": "Not available", "brand": "1", "image": "N/A", "color": "-", "price": "0" }] 

var str = '[{"sno":"1","code":"bp150mb","quantity":null,"name":"mudguard","company":"bajaj","vehicle":"pulsar","brand":"1","image":"N/A","color":"Black","price":"0"},{"sno":"7","code":"P","quantity":"5","name":"","company":null,"vehicle":"Not available","brand":"1","image":"N/A","color":"-","price":"0"}]';
var array = $.parseJSON(str);

OR

var array = jQuery.parseJSON(str);

Since question asked for jQuery.

Here is what you need:

 var jsonString = "[{\\"sno\\":\\"1\\",\\"code\\":\\"bp150mb\\",\\"quantity\\":null,\\"name\\":\\"mudguard\\",\\"company\\":\\"bajaj\\",\\"vehicle\\":\\"pulsar\\",\\"brand\\":\\"1\\",\\"image\\":\\"N/A\\",\\"color\\":\\"Black\\",\\"price\\":\\"0\\"},{\\"sno\\":\\"7\\",\\"code\\":\\"P\\",\\"quantity\\":\\"5\\",\\"name\\":\\"\\",\\"company\\":null,\\"vehicle\\":\\"Not available\\",\\"brand\\":\\"1\\",\\"image\\":\\"N/A\\",\\"color\\":\\"-\\",\\"price\\":\\"0\\"}]"; var parsedJsonArray = JSON.parse(jsonString); alert(parsedJsonArray[0]['name']); console.log(parsedJsonArray); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM