[英]Find value from key in JSON Array
How can i check which JSON value exist in JSON Array? 如何检查JSON数组中存在哪个JSON值? Here are my solution:
这是我的解决方案:
var jsonArr = "[{"F_1":"c4024087","F_2":"9a565962","F_3":"23026","F_4":"John","F_5":"Doe"},{"F_1":"dbb88908","F_2":"bc6fd3bb","F_3":"19727","F_4":"Mike","F_5":"Long"}]"
Find the value: 查找值:
var toFind = "9a565962";
var checkObj = jsonArr.find(o => o.F_2 == toFind );
if (typeof checkObj === "undefined") {
console.log("Value " + toFind + " not exists in Array. Do something!");
} else (Object.keys(checkObj).length > 0) {
console.log("Value " + toFind + " exists in Array. Do something else");
}
Is this the best way to find a value in a array? 这是在数组中查找值的最佳方法吗?
$jsondata = file_get_contents("/json/API.php");
$array = json_decode($jsondata,true);
foreach($array as $k=>$val):
if($id =! $val){
echo '<b>id: '.$k.'</b></br>';
$keys = array_keys($val);
foreach($keys as $key):
echo ' '.ucfirst($key).' = '.$val[$key].'</br>';
endforeach;
endforeach;
}
Probably it will solve your problem Best Regards 可能会解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.