如何解析JSON,其字段名称在PHP中没有双引号
这是我收到的这样一个JSON的例子......
[{meta_data: [{name: "HANDLE", value: "2"}], compound: { name: "Numeric", entries: [{meta_data: [{name: "partition", value: "2"}, {name: "metric-id", value: "18474"}, {name: "unit-code", value: "2720"}, {name: "unit", value: "bpm"}], simple: {name: "Basic-Nu-Observed-Value", type: "float", value: "72.000000"}}, {compound: { name: "Absolute-Time-Stamp", entries: [{simple: {name: "century", type: "intu8", value: "20"}}, {simple: {name: "year", type: "intu8", value: "12"}}, {simple: {name: "month", type: "intu8", value: "4"}}, {simple: {name: "day", type: "intu8", value: "11"}}, {simple: {name: "hour", type: "intu8", value: "3"}}, {simple: {name: "minute", type: "intu8", value: "10"}}, {simple: {name: "second", type: "intu8", value: "26"}}, {simple: {name: "sec_fractions", type: "intu8", value: "0"}}] }}] }}]
答案 0 :(得分:1)
手动,因为它没有有效的JSON而没有“。如果要求声明要以JSON格式交换数据,那么它实际上不是你的问题,它是提供问题的JSON的app / person。推回他们并让他们解决问题。
熊说:
我正在修理他们:) thx
好的,你需要修复生成JSON的应用程序部分,而不是消耗它的部分(假设你在消费方面使用标准的json_decode
)。如果是这种情况,您的初始问题确实变得无关紧要,您可能会或可能不需要发布关于如何最好地重新编写代码以生成适当的JSON的新问题。
答案 1 :(得分:0)
这是你在找什么?我在萤火虫上试过这个。
obj = [{meta_data: [{name: "HANDLE", value: "2"}], compound: { name: "Numeric", entries: [{meta_data: [{name: "partition", value: "2"}, {name: "metric-id", value: "18474"}, {name: "unit-code", value: "2720"}, {name: "unit", value: "bpm"}], simple: {name: "Basic-Nu-Observed-Value", type: "float", value: "72.000000"}}, {compound: { name: "Absolute-Time-Stamp", entries: [{simple: {name: "century", type: "intu8", value: "20"}}, {simple: {name: "year", type: "intu8", value: "12"}}, {simple: {name: "month", type: "intu8", value: "4"}}, {simple: {name: "day", type: "intu8", value: "11"}}, {simple: {name: "hour", type: "intu8", value: "3"}}, {simple: {name: "minute", type: "intu8", value: "10"}}, {simple: {name: "second", type: "intu8", value: "26"}}, {simple: {name: "sec_fractions", type: "intu8", value: "0"}}] }}] }}]
console.log(obj[0].meta_data);
<强>输出强>
[Object { name="HANDLE", value="2"}]