角度.js格式化 json 数据

Angular.js format json data

本文关键字:数据 json 格式化 js 角度      更新时间:2023-09-26
"[{rest_id:"2", cate_id:"4", rest_name:"Samraat Curry Hut", adress:"6275 Jarvis Ave, Newark, CA 94560", city:"Newark", state:"New Jersey", country:"US", email_id:"", rest_url:"Samraat-Curry-Hut", phone_no:"(510) 745-7000", rest_image:"http://www.mealhi5.com/images/restaurant/Samraat-Curry-Hut.jpg"}]"

顶部数组我的结果,但我所需的底部数组添加双引号rest_id到"rest_id"所有键添加双引号("(我所需的数组

这个角度的JS是第一个 JSON 是我的输入和输出第二个数组

[{"rest_id":"2", "cate_id":"4", "rest_name":"Samraat Curry Hut", "adress":"6275 Jarvis Ave, Newark, CA 94560", "city":"Newark", "state":"New Jersey", "country":"US", "email_id":"", "rest_url":"Samraat-Curry-Hut", "phone_no":"(510) 745-7000", "rest_image":"http://www.mealhi5.com/images/restaurant/Samraat-Curry-Hut.jpg"}]

看看 JSON.parse(如果你想把它用作 JSON 对象(

var foo = JSON.parse("[{rest_id:"2", ...}]");
在这种情况下

,您可以使用常规表达做一件事:-

var a= JSON.stringify([{"rest_id":"2", "cate_id":"4", "rest_name":"Samraat Curry Hut", "adress":"6275 Jarvis Ave, Newark, CA 94560", "city":"Newark", "state":"New Jersey", "country":"US", "email_id":"", "rest_url":"Samraat-Curry-Hut", "phone_no":"(510) 745-7000", "rest_image":"http://www.mealhi5.com/images/restaurant/Samraat-Curry-Hut.jpg"}]);
a=a.replace(/"('w+)"'s*:/g, '$1:');

小提琴