javascript - 从 JSON 创建对象

标签 javascript ajax json parsing object

对于这个问题,我看到了很多不同的答案,并尝试将他们的代码应用到我的项目中,但这些解决方案似乎都不适用于我拥有的数据。

我需要将此输出转换为多个对象:

[{"creature":{"id":1,"name":"R.I.P.","sprite_location":null,"health_points":0,"attack":0,"defense":0,"action_points ":0,"attack_cost":0}},{"creature":{"id":2,"name":"R.I.P.","sprite_location":"http://chunkofwhat.com/games/Parousia/sprites/rip.gif","health_points":0,"attack":0,"defense":0,"action_points":0,"attack_cost":0}},{"creature":{"id":3, “名称”:“公牛。”,“sprite_location”:“http://chunkofwhat.com/games/Parousia/sprites/bull.gif”,“health_points”:50,“攻击”:8,“防御”:20 ,"action_points":9,"attack_cost":5}},{"creature":{"id":4,"name":"吞下去。","sprite_location":"http://chunkofwhat.com/games/Parousia/sprites/swallow.gif","health_points":30,"attack":12,"defense":10,"action_points":13,"attack_cost":5}},{"creature":{"id ":5,"name":"Kappa。","sprite_location":"http://chunkofwhat.com/games/Parousia/sprites/kappa.gif","health_points":40,"attack":6,"防御":15,"action_points":9,"attack_cost":3}},{"creature":{"id":6,"name":null,"sprite_location":null,"health_points":null,"攻击":null,"防御":null,"action_points":null,"attack_cost":null}}]

当我尝试 jQuery.parseJSON() 时,它只给了我一堆 [object Object],但我无法引用 Brevets[1].id 等。

再说一遍,我知道这是一个常见问题。我确实经历过很多其他例子,但它们对我来说并不奏效。

谢谢。

最佳答案

每个对象都有一个属性 (creature),其值为另一个对象。

result_of_parsing_json[1].creature.id

关于javascript - 从 JSON 创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10043336/

相关文章:

javascript - 单击按钮时代码无法正常执行 php 文件

jquery - Ajax 表单被 client_side_validations gem 破坏?

python - pretty-print JSON

javascript - 为什么在使用 reactjs Hook 时会出现 "TypeError: react__WEBPACK_IMPORTED_MODULE_1___default.a.useState is not a function"错误?

javascript - 如何在 IE11 中禁用平滑滚动

jquery - 如何在 CherryPy 中接收 AJAX 数据

php json_decode 删除具有空值的属性

javascript - 如何展平 JSON 嵌套对象,同时保留 Nodejs 中的内部 {}?

javascript - jQuery:绑定(bind)一个可以处理其子事件的事件监听器

javascript - 使用 Jquery : Comparing Two Arrays for ANY Match