简体   繁体   English

用jQuery过滤JSON数据

[英]Filter JSON data with jquery

Hi I have a JSON format of the following - 嗨,我有以下JSON格式-

{  
   "0":{  
      "name":"example",
      "age":"21"
   },
   "1":{
      "name":"example2",
      "age":"22"
   }
}

I want to convert it to the following format with jQuery - 我想使用jQuery将其转换为以下格式-

   {  
      "name":"example",
      "age":"21"
   },
   {
      "name":"example2",
      "age":"22"
   }

removing numbering from keys. 从键中删除编号。 Please suggest. 请提出建议。

You really do not need JQuery for this. 您真的不需要JQuery。 You can use Object.values() function to get an array of values for each property in the object: 您可以使用Object.values()函数获取对象中每个属性的值数组:

 const input = { "0":{ "name":"example", "age":"21" }, "1":{ "name":"example2", "age":"22" } } const result = Object.values(input) console.log(result) 

I assume your desired result is an array. 我假设您想要的结果是一个数组。

var json = JSON.parse("your json");
var keys = Object.getOwnPropertyNames(b);
for(var i=o;i<keys.length;i++){
  console.log(b[keys[i]]);
}

Here you go "numbering" removed is over btn Storing parsed objects should be stored in collections, and keys are required to exist in objects. 在这里,您可以通过btn除去“编号”,将已解析的对象存储在集合中,并且键必须存在于对象中。 please refer to 请参阅

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM