首頁 >後端開發 >php教程 >截取多个JSON的参数值遇到问题。

截取多个JSON的参数值遇到问题。

WBOY
WBOY原創
2016-06-23 13:58:50855瀏覽

POST获取的JSON数据  [{"Name":"PM","Value":"224"},{"Name":"WD","Value":"25"},{"Name":"SD","Value":"34"},]

如何截取 Name=WD 的Value?
求代码。


回复讨论(解决方案)

最简单的,循环查找呗。

$json = '[{"Name":"PM","Value":"224"},{"Name":"WD","Value":"25"},{"Name":"SD","Value":"34"}]';$jsonArr = json_decode($json) ;foreach ($jsonArr as  $value) {	if($value->Name == 'WD'){		echo $value->Value."<br />";	}}

$s = '[{"Name":"PM","Value":"224"},{"Name":"WD","Value":"25"},{"Name":"SD","Value":"34"}]';$t = array_filter(json_decode($s), function($v) { return $v->Name == 'WD'; });echo current($t)->Value; //25

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn