[英]how to read json data in php codeigniter
以下是我使用ajax发送到php控制器的json数据
[
{
"First":"A,b"
},
{
"Second":""
},
{
"Third":""
},
{
"Fourth":""
},
{
"Fifth":""
},
{
"Sixth":""
},
{
"Seventh":""
},
{
"Eight":""
},
{
"Ninth":""
},
{
"Tenth":""
}
]
我如何读取值并将其存储在 php 变量中或使用带有上述 json 字符串的循环
您需要使用json_decode()
来解码 json 字符串,而不是使用foreach()
循环。
print_r(json_decode($jsonString,TRUE)); // will return response in an array
print_r(json_decode($jsonString)); // will return response in an object
您可以将数据读取为:
$decoded = json_decode($jsonString,TRUE);
foreach( $decoded as $key => $value ){
// print values
// print key
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.