以下是我使用ajax发送到php控制器的json数据
[
{
"First":"A,b"
},
{
"Second":""
},
{
"Third":""
},
{
"Fourth":""
},
{
"Fifth":""
},
{
"Sixth":""
},
{
"Seventh":""
},
{
"Eight":""
},
{
"Ninth":""
},
{
"Tenth":""
}
]
我如何读取值并将其存储在php变量中或使用上面的json字符串循环
答案 0 :(得分:0)
您需要使用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
}
答案 1 :(得分:0)