如何在console.log中打印json数据 [英] how to print json data in console.log

查看:1773
本文介绍了如何在console.log中打印json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从javascript访问json数据。请帮助我如何从javascript中的json数据访问数据。

I cant access json data from javascript. Please help me how to access data from json data in javascript.

我有一个json数据,如

i have a json data like

{"success":true,"input_data":{"quantity-row_122":"1","price-row_122":" 35.1 "}}

我尝试过console.log(数据)但是记录打印对象对象

i have tried console.log(data) but log print object object

success:function(data){
     console.log(data);
}

如何打印console.log特定数据?
i需要打印
quantity-row_122 = 1
price-row_122 = 35.1

how to print console.log particular data? i need to print quantity-row_122 = 1 price-row_122 = 35.1

推荐答案

console.log(JSON.stringify(data))将满足您的需求。我假设您正在使用基于代码的jQuery。

console.log(JSON.stringify(data)) will do what you need. I'm assuming that you're using jQuery based on your code.

如果您想要这两个特定值,您可以访问它们并将它们传递给 log

If you're wanting those two particular values, you can just access those and pass them to log.

console.log(data.input_data['quantity-row_122']); 
console.log(data.input_data['price-row_122']); 

这篇关于如何在console.log中打印json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆