2016-10-01 107 views
0

以下以下是其中我被使用AJAX如何在PHP讀取JSON數據笨

[ 
    { 
     "First":"A,b" 
    }, 
    { 
     "Second":"" 
    }, 
    { 
     "Third":"" 
    }, 
    { 
     "Fourth":"" 
    }, 
    { 
     "Fifth":"" 
    }, 
    { 
     "Sixth":"" 
    }, 
    { 
     "Seventh":"" 
    }, 
    { 
     "Eight":"" 
    }, 
    { 
     "Ninth":"" 
    }, 
    { 
     "Tenth":"" 
    } 
] 

我怎樣才能讀取值發送到PHP控制器和存儲它在PHP變量或使用環與上述JSON數據json字符串

+1

可能的複製[用PHP解析JSON文件](http://stackoverflow.com/questi ons/4343596/parsing-json-file-with-php) –

回答

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 
} 
+0

是的,我已經解碼了,但我不知道如何從解碼中讀取或提取數據 –

+0

@ rahim-shaikh檢查更新並使用foreach – devpro