为了账号安全,请及时绑定邮箱和手机立即绑定

需要从 Object Literal(JSON 字符串/对象)中找到键值对

需要从 Object Literal(JSON 字符串/对象)中找到键值对

慕少森 2022-01-20 17:24:24
是的,我已经阅读了有关 json 对象的内容 http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/我想搜索 KEY "f03eb90f-6b5e-4b26-bd9f-bad788b7edac"并检索可能为 null /no / yes 的值小提琴在这里:https : //jsfiddle.net/4vse3uw1/试图创建一个数组并将该数据推入其中,然后运行一个 for 循环var arr = [];arr.push(d)console.log(arr)for(props in arr) {    if(arr[props] == "f03eb90f-6b5e-4b26-bd9f-bad788b7edac") {        //doSomething();       console.log(props)    }}然后我在尝试for(var i = 0; i < arr.length; i++){   console.log(i)}var d = [{"00ee9adf-1525-4d1c-a4d7-54f43fa65ae4":"否","0194abfe-8f24-485f-a129-03011ac930a6":"否","01f97094-7f5f-4db5-8fbf-735604b5d76f|Sub1" :"99","0a6f5fe2-0585-410d-a6c1-47b264ccd4fe|Pstor":"","22166f02-a7a3-4648-932d-319c39097659|Sub1":"0","24dc62c0-831b-4195-866f-ce655c31c2ff |Sub1":["34343"],"2aa8f2a4-68d5-4c46-8aaa-41e4544d255e":"否","2b58270e-e3d5-4c3a-8ab1-c284638bfcd9":"否","2d25bc5c-d0d6-4f0e-ba01 -964be54023b1":"否","306be1f4-1b2e-42b3-875e-d2cd0961d1b6":"否","388d72f5-86d7-41f1-9ab2-e8074611ef67":["西班牙裔或拉丁裔","亚洲人","美洲印第安人"或阿拉斯加原住民”,“黑人或非裔美国人”,"夏威夷原住民或其他太平洋岛民","White"],"3b8c04f6-eefe-4ff9-8530-6d037483ea9a|Name":"Moorthy Subbarayan Parthiban","3b8c04f6-eefe-4ff9-8530-6d037483ea9a|Taken_when":"2019 -08-22","3f3943ac-a1a6-4756-8561-f13941783b02":"否","40109054-a7bd-4ec7-b9e1-caa859e1bb0e|Sub1":"234234","46180c0c-d5e7-4de3-b1a1-994309ada9 ":"没有","4bbcdeb8-ea11-4d0d-8727-c805b9b86328":"没有","51eb721d-8312-4696-8f33-d5e3ac51fbb3":"没有","5254270c-72e6-4970-a8a0-9c6a237343e6": "否","5e605a61-41e3-47ac-9441-1a68b6f804f9":"否","601cd274-27d3-4734-b055-931568bad3dc|Sub1":["345345324"],"60f2dfdf-60d4-455f-b19215-2b653a5 “:“不”,”6259e017-9f5d-4ecc-abe2-b87d235f5400":["在家(通过学校系
查看完整描述

2 回答

?
慕容森

TA贡献1853条经验 获得超18个赞

事实证明,您的数组只是一个大对象的元素。您可以只访问该对象上所需的属性。


var d = [{"00ee9adf-1525-4d1c-a4d7-54f43fa65ae4":"No","0194abfe-8f24-485f-a129-03011ac930a6":"No","01f97094-7f5f-4db5-8fbf-735604b5d76f|Sub1":"99","0a6f5fe2-0585-410d-a6c1-47b264ccd4fe|Pstor":"","22166f02-a7a3-4648-932d-319c39097659|Sub1":"0","24dc62c0-831b-4195-866f-ce655c31c2ff|Sub1":["34343"],"2aa8f2a4-68d5-4c46-8aaa-41e4544d255e":"No","2b58270e-e3d5-4c3a-8ab1-c284638bfcd9":"No","2d25bc5c-d0d6-4f0e-ba01-964be54023b1":"No","306be1f4-1b2e-42b3-875e-d2cd0961d1b6":"No","388d72f5-86d7-41f1-9ab2-e8074611ef67":["Hispanic or Latino","Asian","American Indian or Alaska Native","Black or African American","Native Hawaiian or other Pacific Islander","White"],"3b8c04f6-eefe-4ff9-8530-6d037483ea9a|Name":"Moorthy Subbarayan Parthiban","3b8c04f6-eefe-4ff9-8530-6d037483ea9a|Taken_when":"2019-08-22","3f3943ac-a1a6-4756-8561-f13941783b02":"No","40109054-a7bd-4ec7-b9e1-caa859e1bb0e|Sub1":"234234","46180c0c-d5e7-4de3-b1a1-994309ada997":"No","4bbcdeb8-ea11-4d0d-8727-c805b9b86328":"No","51eb721d-8312-4696-8f33-d5e3ac51fbb3":"No","5254270c-72e6-4970-a8a0-9c6a237343e6":"No","5e605a61-41e3-47ac-9441-1a68b6f804f9":"No","601cd274-27d3-4734-b055-931568bad3dc|Sub1":["345345324"],"60f2dfdf-60d4-455f-b195-2b653a5a0921":"No","6259e017-9f5d-4ecc-abe2-b87d235f5400":["Home-based (through school system)"],"6b42f9d6-9958-4349-bcee-ec71b60cf3cd":"No","6d248f44-8903-4c4e-8fcf-ae1d06f22bf1|Pstor":"","74e5954b-a013-47c0-b866-ab5ad5936b98":"No","8029492b-2bb6-4e8a-8ce4-f875326b0914":["Other"],"82419136-0786-4776-b288-59c0effad5b1":"No","85bbffd5-1f35-4bf9-b422-1a0db7c5699c":"No","acbe81a3-630c-4bb4-b9da-59cdb6d719b3|Pstor":"","b78303d8-6e46-473b-8f45-46c7b7b34bf2":"No","bad38be6-2975-4420-baef-836609bc3ab2":"No","c4dc3e49-9159-4035-a637-75717c39c710":"No","c884af20-289f-429a-b1fe-4a09b0b1178f":"Yes","cf935b3f-3e9f-467a-ac97-80547950ae21":"No","d108d6d3-7c6a-4c47-b2fe-00a1405431c2":"No","d2e5240b-5e8a-48f9-bd3b-4dda3c671049":"No","f157187d-578f-4df1-a490-7392eb1725f8":"No","f1a67ea5-802a-4d9b-97cb-70880dd30dda":"No","79d4fe32-a923-42ac-87fe-b539bbc1c942|Address":"53497 ELLEN AVENUE ,FORT WORTH , TX , 76123","79d4fe32-a923-42ac-87fe-b539bbc1c942|Phone":"1822703077","031e4e95-589a-45c2-858a-cf00d87ead73|Multi":{"031e4e95-589a-45c2-858a-cf00d87ead73|Pstor":"","031e4e95-589a-45c2-858a-cf00d87ead73|Pstordesc":""},"13f4c238-1d3e-4aaf-9d3e-985face52646|Multi":{"13f4c238-1d3e-4aaf-9d3e-985face52646|Pstor":"","13f4c238-1d3e-4aaf-9d3e-985face52646|Pstordesc":""},"18772eac-d2cb-43b4-9d6b-4302c842c817|Multi":{"18772eac-d2cb-43b4-9d6b-4302c842c817|Pstor":"","18772eac-d2cb-43b4-9d6b-4302c842c817|Pstordesc":""},"1fbef3a4-d772-434e-bf2c-c58a3e53d5f0|Multi":{"1fbef3a4-d772-434e-bf2c-c58a3e53d5f0|Pstor":"","1fbef3a4-d772-434e-bf2c-c58a3e53d5f0|Pstordesc":""},"53897f32-a24a-47b9-ab91-fa8e9abd003f|Multi":{"53897f32-a24a-47b9-ab91-fa8e9abd003f|Pstor":"","53897f32-a24a-47b9-ab91-fa8e9abd003f|Pstordesc":""},"57461fe2-f9cd-4a0d-b046-05ff09c7b5d2|Multi":{"57461fe2-f9cd-4a0d-b046-05ff09c7b5d2|Pstor":"","57461fe2-f9cd-4a0d-b046-05ff09c7b5d2|Pstordesc":""},"5d64941f-66d3-4acc-b3e0-9beb98ab4f63|Multi":{"5d64941f-66d3-4acc-b3e0-9beb98ab4f63|Pstor":"","5d64941f-66d3-4acc-b3e0-9beb98ab4f63|Pstordesc":""},"626f564e-2c3c-4a99-a49b-d48fb6aaa0a2|Multi":{"706a8a35-ea0f-48a6-a4a4-0da6c9bc409b|Pstor":"","9375189a-f2d4-436e-8d30-1d36345305f0|Pstor":"","91753849-0475-48e8-9b6f-7967f3ee4985|Pstor":""},"7646123e-20a9-4e6d-aff5-c4fb8c044da8|Multi":{"7646123e-20a9-4e6d-aff5-c4fb8c044da8|Pstor":"","7646123e-20a9-4e6d-aff5-c4fb8c044da8|Pstordesc":""},"a3199588-d387-4b46-9a22-8038bcb11260|Multi":{"a3199588-d387-4b46-9a22-8038bcb11260|Pstor":"","a3199588-d387-4b46-9a22-8038bcb11260|Pstordesc":""},"c13030d4-a9db-411f-b96f-eee1057ec86d|Multi":{"c13030d4-a9db-411f-b96f-eee1057ec86d|Pstor":"","c13030d4-a9db-411f-b96f-eee1057ec86d|Pstordesc":""},"c60219b6-5376-4001-8490-016e761046c7|Multi":{"c60219b6-5376-4001-8490-016e761046c7|Pstor":"","c60219b6-5376-4001-8490-016e761046c7|Pstordesc":""},"ce77da8b-21a4-4270-ba07-250838ee34a6|Multi":{"ce77da8b-21a4-4270-ba07-250838ee34a6|Pstor":"","ce77da8b-21a4-4270-ba07-250838ee34a6|Pstordesc":""},"d3d41889-a315-4aa2-b85a-2bb1249a194d|Multi":{"d3d41889-a315-4aa2-b85a-2bb1249a194d|Pstor":"","d3d41889-a315-4aa2-b85a-2bb1249a194d|Pstordesc":""},"d9718a0f-5918-483a-b21f-5272326fe1f1|Multi":{"d9718a0f-5918-483a-b21f-5272326fe1f1|Pstor":"","d9718a0f-5918-483a-b21f-5272326fe1f1|Pstordesc":""},"ddb42d2d-9a03-4cb4-83ec-f5b8391a188e|Multi":{"ddb42d2d-9a03-4cb4-83ec-f5b8391a188e|Pstor":"","ddb42d2d-9a03-4cb4-83ec-f5b8391a188e|Pstordesc":""},"f2dd3e39-3011-41ed-8a8d-14a679370070|Multi":{"f2dd3e39-3011-41ed-8a8d-14a679370070|Pstor":"","f2dd3e39-3011-41ed-8a8d-14a679370070|Pstordesc":""},"f03eb90f-6b5e-4b26-bd9f-bad788b7edac":"No","pageNo":0}]


const found = d[0]["f03eb90f-6b5e-4b26-bd9f-bad788b7edac"];


console.log(found);


查看完整回答
反对 回复 2022-01-20
?
哈士奇WWW

TA贡献1799条经验 获得超6个赞

   // let suppose you have all results are in this array

    let array = // big array here


    //it will search all the objects that the array have 

    //and create a array with all the results :)

    let allValues=array.map(object=>{

      return object["f03eb90f-6b5e-4b26-bd9f-bad788b7edac"]

    })


查看完整回答
反对 回复 2022-01-20
  • 2 回答
  • 0 关注
  • 149 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信