妄徒之命 2011-06-19 17:26 采纳率: 100%
浏览 70

解析JSON ajax var

I like translate my json-Data to an JS object or assign it to a variable..

$.ajaxSetup({
type: "POST",
url: "_class/queries.php",
dataType:"json"
});

var obj;    

$.ajax({
   data: querystring,
   success: function(data){

     console.log(data);

     alert(data[0].vname);

     //obj = JSON.parse(JSON.stringify(data));

     obj = data;

     console.log(obj[0].vname);//<-- prints the expected property 
   }

 });

console.log("return "+obj);//<-- undefined?
return obj;

}

the alert print out the right property-value but somehow the eval-function produces an pars error? I've tryed jQuery.parseJSON but wont work either?

  • 写回答

2条回答 默认 最新

  • weixin_33724046 2011-06-19 17:41
    关注

    The json variable contains already parsed value - the data returned by the server. Why do you you need to eval it?

    obj = data;
    

    is enough.

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?