javascript - 如何在 console.log 中打印 JSON 数据?

标签 javascript arrays json

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

我有一个类似的 JSON 数据

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

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

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

如何打印 console.log 特定数据? 我需要打印

quantity-row_122 = 1
price-row_122 = 35.1

最佳答案

console.log(JSON.stringify(data)) 会做你需要的。我假设您正在使用基于您的代码的 jQuery。

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

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

关于javascript - 如何在 console.log 中打印 JSON 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28149462/

相关文章:

c++ - 模板结构作为数组

c# - 带有 POST 的 ASP.NET MVC JSON 正文

ruby-on-rails - Rails : Using JBuilder views outside of the view context

python - Flask Json json.decoder.JSONDecodeError : Expecting value: line 1 column 1 (char 0)

javascript - 动态匿名 js 函数不起作用

javascript - 像 Facebook 一样突出文本区域内的文本

javascript - 查找是否已经存在,JS和Lodash

javascript - Chrome扩展异步问题

javascript - 在javascript中将复杂类型的字符串数组转换为json

python - 检查不同 numpy 数组中的相同行