Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的JSONArray解析_Php_Json - Fatal编程技术网

PHP中的JSONArray解析

PHP中的JSONArray解析,php,json,Php,Json,我正在尝试解析JSONArray,但无法解析。我的回答是空的 我的JSONArray: ["{\"mapurl\":\"http:\\\/\\\/maps.google.com\\\/maps?q=17.XXXXXXXX,78.xxxxxxx\",\"caller\":\"+91xxxxxxxxx\",\"id\":1,\"reciever\":\"+91xxxxxxxx\",\"timpestamp\":\"3\"}","{\"mapurl\":\"http:\\\/\\\/maps.goog

我正在尝试解析JSONArray,但无法解析。我的回答是空的

我的JSONArray:

["{\"mapurl\":\"http:\\\/\\\/maps.google.com\\\/maps?q=17.XXXXXXXX,78.xxxxxxx\",\"caller\":\"+91xxxxxxxxx\",\"id\":1,\"reciever\":\"+91xxxxxxxx\",\"timpestamp\":\"3\"}","{\"mapurl\":\"http:\\\/\\\/maps.google.com\\\/maps?q=17.xxxxxxx,78.xxxxxxx\",\"caller\":\"+91xxxxxxxxxx\",\"id\":2,\"reciever\":\"+91xxxxxxxxxx\",\"timpestamp\":\"3\"}"]
我将这个JSONArray作为参数“add”中的GET请求从Android传递

我的PHP代码:

<?php
if (isset($_GET['add'])) {
$jsonData = $_GET['add'];
$phpArray = json_decode($jsonData);
var_dump($phpArray);
}
else{
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>

看起来您的PHP配置仍然启用了不推荐的功能。在PHP配置中禁用magic_quotes,或者尝试使用
stripslashes()
函数删除magic_quotes功能添加的额外反斜杠:


$jsonData=stripslashes($_GET['add'])

我试用了你的json。它实际上是有效的。我认为这是因为您正在使用
$\u GET
传递数据。我建议您使用
post
发送Json数据。但是,如果必须使用
$\u GET
来发送数据,请确保
JSON.stringify()
it。但是如果你的数据比这里的要长,你可能会有一个被截断的url,当然,这就是数据


这样,您当前的代码非常有效,包括您的json。

这里实际上有几个json编码的对象作为字符串存储在json数组中。你的编码器有点怪

您只需在阵列中循环并解码每个部分:

$phpArray = array();
foreach(json_decode($_GET['add']) as $part) {
    $phpArray[] = json_decode($part, true);
}
但是你真的应该从源头上解决它


但不确定为什么会出现空值。您至少应该使用代码获取一个字符串数组。我测试了自己,并做了…

当您执行
echo$\u GET['add']时会发生什么
在代码顶部?@RichardBernards让我检查一下我强烈建议使用POST而不是GET。如果您的GET为NULL,则您的JSON编码不正确。如果($phpArray==null)回显json\u last\u error\u msg(),则使用
看到了该错误的代码>看到了该错误的代码>看到了该错误的代码。@理查德伯纳德(理查德伯纳德(理查德伯纳德<理查德伯纳德<理查德伯纳德<理查德伯纳德<代码<方方方称称称称此次代码>看到了该错误的错误。理查德伯伯伯纳德(理查德伯伯纳德<<儿童儿童儿童儿童<<<<<<<<主要主要主要主要的代码<<<<<<<方方方方方方<此次此次此次此次代码>的代码<该该该网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页网页<<<<<<<<上述上述上述上述上述上述上述上述上述上述上述上述上述上述的主要主要主要主要主要主要主要主要主要主要主要的http http http http http::::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\“3\\\\\\\\\\\\\”、“{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\“,\\\\\\\\”:\\\“+91xxxxxxxx\\\”,\\\\\“id\\\”:2,\\\\“Receiver\\”:\\\“+91xxxxxxxx\\”,\\\\\“timpestamp\\”:\\\\“3\\\”]NULL
这是我得到的响应