Javascript JSON解码:混合类型-无效语法错误
这是我的JSON示例Javascript JSON解码:混合类型-无效语法错误,javascript,php,arrays,json,object,Javascript,Php,Arrays,Json,Object,这是我的JSON示例 {"tasks" : [ { "id" : "27604_11", "quality" : "A4", "position" : "183567", "profile" : "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg", "type" : "im
{"tasks" : [
{
"id" : "27604_11",
"quality" : "A4",
"position" : "183567",
"profile" : "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg",
"type" : "image",
"valid" : "24 days",
"member" : {
"carrier" : null,
"zone" : null,
"offd" : null },
"taketime" : "4minutes",
"listeners" : {
"count" : 0 },
"message" : "stay prepared",
"level" : "High"
},
{
"id" : "27604_12",
"quality" : "B3",
"position" : "183569",
"profile" : "https:\/\/example.com\/gallery\/profiles\/8232_1.jpg",
"type" : "image",
"valid" : "11 days",
"member" : {
"carrier" : null,
"zone" : null,
"offd" : null },
"taketime" : "7minutes",
"listeners" : {
"count" : 2 },
"message" : "ready",
"level" : "High"
},
{
"id" : "73754_35",
"quality" : "A3",
"position" : "13542",
"profile" : "https:\/\/example.com\/gallery\/profiles\/1235_5.jpg",
"type" : "image",
"valid" : "5 days",
"member" : {
"carrier" : null,
"zone" : null,
"offd" : null },
"taketime" : "22minutes",
"listeners" : {
"count" : 0 },
"message" : "Good",
"level" : "Normale" }
],
"start_poz" : "36774263743"
}
{"tasks" : [
{
"id" : "27604_11",
"quality" : "A4",
"position" : "183567",
"profile" : "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg",
"type" : "image",
"valid" : "24 days",
"member" : {
"carrier" : null,
"zone" : null,
"offd" : null },
"taketime" : "4minutes",
"listeners" : {
"count" : 0 },
"message" : "stay prepared",
"level" : "High"
},
{
"id" : "27604_12",
"quality" : "B3",
"position" : "183569",
"profile" : "https:\/\/example.com\/gallery\/profiles\/8232_1.jpg",
"type" : "image",
"valid" : "11 days",
"member" : {
"carrier" : null,
"zone" : null,
"offd" : null },
"taketime" : "7minutes",
"listeners" : {
"count" : 2 },
"message" : "ready",
"level" : "High"
},
{
"id" : "73754_35",
"quality" : "A3",
"position" : "13542",
"profile" : "https:\/\/example.com\/gallery\/profiles\/1235_5.jpg",
"type" : "image",
"valid" : "5 days",
"member" : {
"carrier" : null,
"zone" : null,
"offd" : null },
"taketime" : "22minutes",
"listeners" : {
"count" : 0 },
"message" : "Good",
"level" : "Normale" }
],
"start_poz" : "36774263743"
}
{"tasks" : [
{
"id" : "27604_11",
"quality" : "A4",
"position" : "183567",
"profile" : "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg",
"type" : "image",
"valid" : "24 days",
"member" : {
"carrier" : null,
"zone" : null,
"offd" : null },
"taketime" : "4minutes",
"listeners" : {
"count" : 0 },
"message" : "stay prepared",
"level" : "High"
},
{
"id" : "27604_12",
"quality" : "B3",
"position" : "183569",
"profile" : "https:\/\/example.com\/gallery\/profiles\/8232_1.jpg",
"type" : "image",
"valid" : "11 days",
"member" : {
"carrier" : null,
"zone" : null,
"offd" : null },
"taketime" : "7minutes",
"listeners" : {
"count" : 2 },
"message" : "ready",
"level" : "High"
},
{
"id" : "73754_35",
"quality" : "A3",
"position" : "13542",
"profile" : "https:\/\/example.com\/gallery\/profiles\/1235_5.jpg",
"type" : "image",
"valid" : "5 days",
"member" : {
"carrier" : null,
"zone" : null,
"offd" : null },
"taketime" : "22minutes",
"listeners" : {
"count" : 0 },
"message" : "Good",
"level" : "Normale" }
],
"start_poz" : "36774263743"
}
这是php:
<?php
$file = file_get_contents("in.txt");
$json = json_decode($file, true);
那就行了
你能告诉我我在语法上的错误在哪里吗。。和也许您还可以帮助我了解如何通过从任务数组中获取值的每个循环来获取start\u poz值
非常感谢您,祝您新年快乐!) jsonlint.com说:
Error: Parse error on line 58:
...z": "36774263743"} { "tasks": [{ "id
----------------------^
Expecting 'EOF', '}', ',', ']', got '{'
所以当它到达那个{时,它处于一个只有
- 文件的结尾
- 一个紧密的卷曲括号
- 逗号
- 还是一个紧括号
Error: Parse error on line 58:
...z": "36774263743"} { "tasks": [{ "id
----------------------^
Expecting 'EOF', '}', ',', ']', got '{'
所以当它到达那个{时,它处于一个只有
- 文件的结尾
- 一个紧密的卷曲括号
- 逗号
- 还是一个紧括号
将是有效的。在顶级输入文件中有三个单独的JSON对象。您需要将整个输入包装为一个数组
[…]
或单独分析每个对象。在顶级输入文件中有三个单独的JSON对象。您需要将整个输入包装为一个数组[…]
或单独解析每一个。吉姆答对了,这是正确的JSON
{
"tasklist": [{
"tasks": [{
"id": "27604_11",
"quality": "A4",
"position": "183567",
"profile": "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg",
"type": "image",
"valid": "24 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "4minutes",
"listeners": {
"count": 0
},
"message": "stay prepared",
"level": "High"
}, {
"id": "27604_12",
"quality": "B3",
"position": "183569",
"profile": "https:\/\/example.com\/gallery\/profiles\/8232_1.jpg",
"type": "image",
"valid": "11 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "7minutes",
"listeners": {
"count": 2
},
"message": "ready",
"level": "High"
}, {
"id": "73754_35",
"quality": "A3",
"position": "13542",
"profile": "https:\/\/example.com\/gallery\/profiles\/1235_5.jpg",
"type": "image",
"valid": "5 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "22minutes",
"listeners": {
"count": 0
},
"message": "Good",
"level": "Normale"
}],
"start_poz": "36774263743"
}, {
"tasks": [{
"id": "27604_11",
"quality": "A4",
"position": "183567",
"profile": "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg",
"type": "image",
"valid": "24 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "4minutes",
"listeners": {
"count": 0
},
"message": "stay prepared",
"level": "High"
}, {
"id": "27604_12",
"quality": "B3",
"position": "183569",
"profile": "https:\/\/example.com\/gallery\/profiles\/8232_1.jpg",
"type": "image",
"valid": "11 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "7minutes",
"listeners": {
"count": 2
},
"message": "ready",
"level": "High"
}, {
"id": "73754_35",
"quality": "A3",
"position": "13542",
"profile": "https:\/\/example.com\/gallery\/profiles\/1235_5.jpg",
"type": "image",
"valid": "5 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "22minutes",
"listeners": {
"count": 0
},
"message": "Good",
"level": "Normale"
}],
"start_poz": "36774263743"
}, {
"tasks": [{
"id": "27604_11",
"quality": "A4",
"position": "183567",
"profile": "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg",
"type": "image",
"valid": "24 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "4minutes",
"listeners": {
"count": 0
},
"message": "stay prepared",
"level": "High"
}, {
"id": "27604_12",
"quality": "B3",
"position": "183569",
"profile": "https:\/\/example.com\/gallery\/profiles\/8232_1.jpg",
"type": "image",
"valid": "11 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "7minutes",
"listeners": {
"count": 2
},
"message": "ready",
"level": "High"
}, {
"id": "73754_35",
"quality": "A3",
"position": "13542",
"profile": "https:\/\/example.com\/gallery\/profiles\/1235_5.jpg",
"type": "image",
"valid": "5 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "22minutes",
"listeners": {
"count": 0
},
"message": "Good",
"level": "Normale"
}],
"start_poz": "36774263743"
}]
}
吉姆答对了,这是正确的JSON
{
"tasklist": [{
"tasks": [{
"id": "27604_11",
"quality": "A4",
"position": "183567",
"profile": "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg",
"type": "image",
"valid": "24 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "4minutes",
"listeners": {
"count": 0
},
"message": "stay prepared",
"level": "High"
}, {
"id": "27604_12",
"quality": "B3",
"position": "183569",
"profile": "https:\/\/example.com\/gallery\/profiles\/8232_1.jpg",
"type": "image",
"valid": "11 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "7minutes",
"listeners": {
"count": 2
},
"message": "ready",
"level": "High"
}, {
"id": "73754_35",
"quality": "A3",
"position": "13542",
"profile": "https:\/\/example.com\/gallery\/profiles\/1235_5.jpg",
"type": "image",
"valid": "5 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "22minutes",
"listeners": {
"count": 0
},
"message": "Good",
"level": "Normale"
}],
"start_poz": "36774263743"
}, {
"tasks": [{
"id": "27604_11",
"quality": "A4",
"position": "183567",
"profile": "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg",
"type": "image",
"valid": "24 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "4minutes",
"listeners": {
"count": 0
},
"message": "stay prepared",
"level": "High"
}, {
"id": "27604_12",
"quality": "B3",
"position": "183569",
"profile": "https:\/\/example.com\/gallery\/profiles\/8232_1.jpg",
"type": "image",
"valid": "11 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "7minutes",
"listeners": {
"count": 2
},
"message": "ready",
"level": "High"
}, {
"id": "73754_35",
"quality": "A3",
"position": "13542",
"profile": "https:\/\/example.com\/gallery\/profiles\/1235_5.jpg",
"type": "image",
"valid": "5 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "22minutes",
"listeners": {
"count": 0
},
"message": "Good",
"level": "Normale"
}],
"start_poz": "36774263743"
}, {
"tasks": [{
"id": "27604_11",
"quality": "A4",
"position": "183567",
"profile": "https:\/\/example.com\/gallery\/profiles\/8764_2.jpg",
"type": "image",
"valid": "24 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "4minutes",
"listeners": {
"count": 0
},
"message": "stay prepared",
"level": "High"
}, {
"id": "27604_12",
"quality": "B3",
"position": "183569",
"profile": "https:\/\/example.com\/gallery\/profiles\/8232_1.jpg",
"type": "image",
"valid": "11 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "7minutes",
"listeners": {
"count": 2
},
"message": "ready",
"level": "High"
}, {
"id": "73754_35",
"quality": "A3",
"position": "13542",
"profile": "https:\/\/example.com\/gallery\/profiles\/1235_5.jpg",
"type": "image",
"valid": "5 days",
"member": {
"carrier": null,
"zone": null,
"offd": null
},
"taketime": "22minutes",
"listeners": {
"count": 0
},
"message": "Good",
"level": "Normale"
}],
"start_poz": "36774263743"
}]
}
是的,但是..对不起,这是什么意思:应该是'EOF'、'}'、'、']',得到了上面说的{我有点新手)))如果你将json粘贴到该页面的表单中,它会显示你的错误。你在一行中发送两个独立的对象,比如
{“foo”:“bar”}{“foo”:“bar”
。它们需要在一个数组中:“bar”},{“foo”:“bar”}]我明白了,但我不明白它为什么错了,我该如何修复它。在我的JSON示例中,我得到了以下结构:{“tasks”:[{array}],“start_poz”:(integer_value)},{“tasks”:[{array}],“start_poz”:(integer_value)},{“tasks”:[{array}],“start_poz”:(integer_value)}我找不到任何手册可以帮助我理解这个语法的错误。有人能解释一下吗?啊哈,谢谢斜视!看起来我开始理解了。需要更多练习)实际上我以前用验证器检查过代码,但我不明白我的问题。谢谢!是的,但是…对不起,这是什么意思:Expe如果你把你的json粘贴到该页面的表单中,它会显示你的错误。你正在发送两个独立的对象,如{“foo”:“bar”}{“foo”:“bar”}{“foo”:“bar”}
,它们需要在一个数组中我明白了,但我不明白为什么它是错误的,我如何修复它。在我的JSON示例中,我得到了以下结构:{“任务”:[{array}],“start_poz”:(整数值)},{“任务”:[{array}],“start_poz”:(整数值)},{“任务”:[{array}],“start_poz”:(整数值)}我找不到任何手册可以帮助我理解这个语法的错误。有人能解释一下吗?啊哈,谢谢斜视!看起来我开始理解了。需要更多练习)事实上我以前用验证器检查过代码,但我不理解我的问题。谢谢!这是完美的答案!我手动处理了o将3个JSON响应合并到一个文件中,但无法找出问题所在。现在我清楚地知道是什么原因造成的。感谢您提供的基础知识帮助!仅供参考,本网站描述的JSON文件中存在安全问题,因此使用对象来组合它们可能比使用数组更好。这是一个完美的答案已过时,无法将3个JSON响应合并到1个文件中,无法找出问题所在。现在我清楚地知道是什么原因导致了这一问题。感谢您提供的基础知识帮助!仅供参考,本网站描述的JSON文件中存在安全性问题,因此最好使用对象来组合它们,而不是使用数组