Convert JSON file in
  • using plain Javascript

前端 未结 2 1130
天涯浪人
天涯浪人 2021-01-26 13:33

I have JSON file that contains :

{
    \"age\": 0,
    \"id\": \"motorola-xoom-with-wi-fi\",
    \"imageUrl\": \"img/phones/motorola-xoom-with-wi-fi.0.jpg\",
            


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-26 14:30

    try this

    var phones = {"age" : "0",  "id" : "motorola-xoom-with-wi-fi",  "imageUrl" : "img/phones/motorola-xoom-with-wi-fi.0.jpg",   "name" : "Motorola XOOM\u2122 with Wi-Fi",  "snippet" : "The Next Next Generation Experience the future with Motorola XOOM with Wi-Fi, the worlds first tablet powered by Android 3.0 (Honeycomb)."};
    
       var arr = phones;
       console.log(arr);
       var out = "
    • age : " + arr.age + "

    • id : " + arr.id + "


    • name : " + arr.name + "

    • snippet : " + arr.snippet + "
    • " document.getElementById("div1").innerHTML = out;

提交回复
热议问题