从JSON数组中的键中查找值 [英] Find value from key in JSON Array

查看:141
本文介绍了从JSON数组中的键中查找值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查JSON数组中存在哪个JSON值?这是我的解决方案:

How can i check which JSON value exist in JSON Array? 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"}]"

查找值:

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 '&nbsp;'.ucfirst($key).' = '.$val[$key].'</br>';
    endforeach;
endforeach;
}

也许可以解决您的问题最好的问候

Probably it will solve your problem Best Regards

这篇关于从JSON数组中的键中查找值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆