简体   繁体   中英

How to get json array in controller js in ionic 1?

My server response like

{"items": [{"item_id":"1","item_name":"Skirt"},
           {"item_id":"2","item_name":"Track"}]}

I need like

items: [
            {
                item_id: 1,
                item_name: 'Skirt'
            },
        {
            item_id: 2,
            item_name: 'Track'
        }
    ]

Please help.

Store json response into one variable

then

<?php
   $jsonresponse=json_decode($json);
   print_r($jsonresponse)
?>

use JSON.parse()

 data ='{"items": [{"item_id":"1","item_name":"Skirt"},{"item_id":"2","item_name":"Track"}]}'; data = JSON.parse(data); console.log(data); 

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