帮忙看一下php如何提取指定字符中间的字符串
原数据好下"1":{"1":"粉条","2":"100"},"2":{"1":"木耳","2":"102"},"3":{"1":"大米","2":"101"}如何提取{}...
原数据好下
"1":{"1":"粉条","2":"100"},"2":{"1":"木耳","2":"102"},"3":{"1":"大米","2":"101"}
如何提取{ }之类的字符串,并循环输出。 展开
"1":{"1":"粉条","2":"100"},"2":{"1":"木耳","2":"102"},"3":{"1":"大米","2":"101"}
如何提取{ }之类的字符串,并循环输出。 展开
1个回答
2019-10-18
展开全部
你在这个字符串外面加上{}就可以解码json,
<?php
$str='{"1":{"1":"粉条","2":"100"},"2":{"1":"木耳","2":"102"},"3":{"1":"大米","2":"101"}}';
$str=json_decode($str,true);
foreach($str as $index){
echo $index[1];
echo $index[2].'<br/>';
}
输出:
粉条100
木耳102
大米101
<?php
$str='{"1":{"1":"粉条","2":"100"},"2":{"1":"木耳","2":"102"},"3":{"1":"大米","2":"101"}}';
$str=json_decode($str,true);
foreach($str as $index){
echo $index[1];
echo $index[2].'<br/>';
}
输出:
粉条100
木耳102
大米101
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询