javascript - Finding value in json string -


below have json string.

{     "id_a0001":{"areaid":"a0001","shopid":"sh004","quantity":14},     "row_info":{"areaid":"varchar","shopid":"varchar","quantity":"int"},     "id_a0002":{"areaid":"a0002","shopid":"sh008","quantity":18} } 

what want jsonobject have id id_a i.e. id_a0001 & id_a0002.

i thinking of using jsonobject.getstring("id_a"), not possible. tell me should below output.

{     "id_a0001":{"areaid":"a0001","shopid":"sh004","quantity":14},     "id_a0002":{"areaid":"a0002","shopid":"sh008","quantity":18} } 

the following code want, assuming object posted stored in obj. in case have json string instead of object, use json.parse() convert string javascript object.

var obj2 = {}; for(var key in obj) {     if(key.substr(0, 4) == 'id_a') {         obj2[key] = obj[key];     } } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -