遍历数组:PHP

Zapper

我的JSON数组:

[\"{\\\"mapurl\\\":\\\"http:\\\\\\/\\\\\\/maps.google.com\\\\\\/maps?q=17.xxxxx5,78.xxxxxx3\\\",\\\"caller\\\":\\\"+91xxxxxx\\\",\\\"id\\\":1,\\\"reciever\\\":\\\"+91xxxxxx\\\",\\\"timpestamp\\\":\\\"3\\\"}\",\"{\\\"mapurl\\\":\\\"http:\\\\\\/\\\\\\/maps.google.com\\\\\\/maps?q=17.xxxxx,78.xxxxx\\\",\\\"caller\\\":\\\"+91xxxxxx\\\",\\\"id\\\":2,\\\"reciever\\\":\\\"+91xxxxx\\\",\\\"timpestamp\\\":\\\"3\\\"}\"]

我在add Parameter中将此JSONArray作为POST请求的一部分传递。

我的代码用于显示数组的内容

$jsonData = stripslashes($_POST['add']);
$phpArray = json_decode($jsonData,true);
foreach ($phpArray as $index => $record) 
{
 echo $record["caller"];
}

我的输出仅是两个大括号。

{{

我不明白怎么了

溢价

您的JSON无效,每个数组不应包含引号。

修复生成的内容,如果不能,则将修复以下内容

$jsonData = stripslashes(stripslashes($jsonData));
$jsonData = str_replace(
  array('"{', '}"'),
  array('{', '}'),
  $jsonData
);

$phpArray = json_decode($jsonData,true);
foreach ($phpArray as $index => $record) 
{
   echo $record["caller"];
}

虽然用作最后的手段,但最好在发送之前修复损坏的JSON。魔术引号也已从PHP中删除。避免使用它

以上输出

+ 91xxxx + 91xxxxx

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章