我有这个字符串
$str = '[{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null}]'
我想把它变成一个变量数组。
我在网上搜索过这样的情况但没找到任何东西。
只有简单的字符串,如'some,test,string'
等。
我知道如何处理这个问题?
答案 0 :(得分:1)
使用json_decode()函数再次转换字符串数组
答案 1 :(得分:0)
此字符串是json编码对象。使用json_decode将此字符串解析为JSON对象。之后,您可以循环迭代并打印所有对象/数组:
$str = '[{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null},{"parousia":null,"proforikos":null,"test":null,"ergasias":null,"telikos":null}]';
$json = json_decode($str);
foreach($json as $obj) {
var_dump((array)$obj);
}
答案 2 :(得分:0)
'[{"parousia":"krishnsa","proforikos":null,"test":null,"ergasias":null,"telikos":n
ULL]}`',
$output = json_decode($str, true);
echo $output[0]["parousia"];