[英]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.