Php json_解码上的最后一个参数数组
大家好,我有这个字符串JSON,我用函数phpPhp json_解码上的最后一个参数数组,php,json,Php,Json,大家好,我有这个字符串JSON,我用函数phpJSON\u decode($var,true) 我收到了这个数组 Array( [0] => Array ( [id] => 4 [name] => Elis ) [1] => Array ( [id] => 5 [name] => Eilbert ))1 数组末尾的最后一个数字“1”是什么?为什么会有?我不想要它我怎么能删除它 在js上,我传递一个用JSON.stringify()转换的数组,
JSON\u decode($var,true)
我收到了这个数组
Array( [0] => Array ( [id] => 4 [name] => Elis )
[1] => Array ( [id] => 5 [name] => Eilbert ))1
数组末尾的最后一个数字“1”是什么?为什么会有?我不想要它我怎么能删除它
在js上,我传递一个用JSON.stringify()转换的数组,结果与第一个JSON代码类似
$user = json_decode($this->input->post('to'),true);
$conv_user_id = array();
foreach ($user as $po) {
$conv_user_id[] = $po['id'];
$conv_user_id[] = $id_user;
}
echo print_r($user);
@explosion phill向我指出,我的json字符串是用[]
包装的,我只传递了一个js中的数组,它是用json.stringify()转换的,这是错误吗?您误用了:
如果要捕获print_r()的输出,请使用return参数。当此参数设置为TRUE时,print_r()将返回信息,而不是打印信息
当return参数为TRUE时,此函数将返回一个字符串。否则,返回值为TRUE
。。。当您将布尔值TRUE
转换为字符串时,会得到1
您误用了:
如果要捕获print_r()的输出,请使用return参数。当此参数设置为TRUE时,print_r()将返回信息,而不是打印信息
当return参数为TRUE时,此函数将返回一个字符串。否则,返回值为TRUE
。。。当您将布尔值TRUE
强制转换为字符串时,您将得到1
json\u decode-解码json字符串
使用json_decode()的常见错误示例
json\u decode-解码json字符串
使用json_decode()的常见错误示例
你的意思是
json\u decode
?请显示您的实际代码,这也是无效的json。它是用[]
包装的吗?你展示了哪种方法?现在我检查出更好了是的,爆炸有了中心点。是用[]包装的吗?我如何删除它?你的意思是json\u decode
?请显示你的实际代码,这也是无效的json。它是用[]
包装的吗?你展示了哪种方法?现在我检查出更好了是的,爆炸有了中心点。是用[]包装的,我怎么能删除它?确切地说,我不知道,但我不是我的问题,但你对我的问题有正确的答案。确切地说,我不知道,但我不是我的问题,但你对我的问题有正确的答案。
$user = json_decode($this->input->post('to'),true);
$conv_user_id = array();
foreach ($user as $po) {
$conv_user_id[] = $po['id'];
$conv_user_id[] = $id_user;
}
echo print_r($user);
echo print_r($user);
<?php
// the following strings are valid JavaScript but not valid JSON
// the name and value must be enclosed in double quotes
// single quotes are not valid
$bad_json = "{ 'bar': 'baz' }";
json_decode($bad_json); // null
// the name must be enclosed in double quotes
$bad_json = '{ bar: "baz" }';
json_decode($bad_json); // null
// trailing commas are not allowed
$bad_json = '{ bar: "baz", }';
json_decode($bad_json); // null
?>