How to parse JSON in JavaScript to take value

后端 未结 6 1255
陌清茗
陌清茗 2020-12-06 23:58

I am really stuck in parsing a JSON string and take it\'s values. I got the JSON string as

{\"user\":{\"id\":\"1\",\"firstname\":\"Freelogin\",\"created\":\         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 00:36

    Json is already some javascript. so parsing is just using eval

    like:

     var foobar = eval(yourjson);
     alert(foobar.user);
    

    Also jquery has some function for it jquery.parseJSON

    like:

       var foobar = $.parseJSON(yourjson);
    

    Jquery is better because it would make some checks and perform better.

提交回复
热议问题