简体   繁体   English

如何从我的Json对象获取所有ID,名称值和位置到数组中

[英]How do I get All ID, Name values and location into array from my Json Object

SO i have json object caleld tabledata array, lets say i want to iterate all objects inside it and grab ids, so output returns 1,2,3,4,5,6,7,8,9,10 and I can also do name, location etc. So i want to select one key and i need all the available values inside. 所以我有json对象calend tabledata数组,可以说我想迭代其中的所有对象并获取id,因此输出返回1,2,3,4,5,6,7,8,9,10,我也可以名称,位置等。所以我想选择一个键,我需要里面的所有可用值。

I have tried looping the object but didint work for me. 我尝试循环对象,但didint为我工作。

for(int i = 0; i < array.length; i++) {
    JSONObject object = (JSONObject) array.get(i);

    String id = object.get("id");
    //and so on
}

var tabledata = [
    {id:1, name:"Oli Bob", location:"United Kingdom", gender:"male", rating:1, col:"red", dob:"14/04/1984"},
    {id:2, name:"Mary May", location:"Germany", gender:"female", rating:2, col:"blue", dob:"14/05/1982"},
    {id:3, name:"Christine Lobowski", location:"France", gender:"female", rating:0, col:"green", dob:"22/05/1982"},
    {id:4, name:"Brendon Philips", location:"USA", gender:"male", rating:1, col:"orange", dob:"01/08/1980"},
    {id:5, name:"Margret Marmajuke", location:"Canada", gender:"female", rating:5, col:"yellow", dob:"31/01/1999"},
    {id:6, name:"Frank Harbours", location:"Russia", gender:"male", rating:4, col:"red", dob:"12/05/1966"},
    {id:7, name:"Jamie Newhart", location:"India", gender:"male", rating:3, col:"green", dob:"14/05/1985"},
    {id:8, name:"Gemma Jane", location:"China", gender:"female", rating:0, col:"red", dob:"22/05/1982"},
    {id:9, name:"Emily Sykes", location:"South Korea", gender:"female", rating:1, col:"maroon", dob:"11/11/1970"},
    {id:10, name:"James Newman", location:"Japan", gender:"male", rating:5, col:"red", dob:"22/03/1998"},
];

In javascript, like this. 在javascript中,就像这样。

 var tabledata = [ {id:1, name:"Oli Bob", location:"United Kingdom", gender:"male", rating:1, col:"red", dob:"14/04/1984"}, {id:2, name:"Mary May", location:"Germany", gender:"female", rating:2, col:"blue", dob:"14/05/1982"}, {id:3, name:"Christine Lobowski", location:"France", gender:"female", rating:0, col:"green", dob:"22/05/1982"}, {id:4, name:"Brendon Philips", location:"USA", gender:"male", rating:1, col:"orange", dob:"01/08/1980"}, {id:5, name:"Margret Marmajuke", location:"Canada", gender:"female", rating:5, col:"yellow", dob:"31/01/1999"}, {id:6, name:"Frank Harbours", location:"Russia", gender:"male", rating:4, col:"red", dob:"12/05/1966"}, {id:7, name:"Jamie Newhart", location:"India", gender:"male", rating:3, col:"green", dob:"14/05/1985"}, {id:8, name:"Gemma Jane", location:"China", gender:"female", rating:0, col:"red", dob:"22/05/1982"}, {id:9, name:"Emily Sykes", location:"South Korea", gender:"female", rating:1, col:"maroon", dob:"11/11/1970"}, {id:10, name:"James Newman", location:"Japan", gender:"male", rating:5, col:"red", dob:"22/03/1998"} ]; for(let i = 0; i < tabledata.length; i++) { const object = tabledata[i]; console.log(object.id) } // or tabledata.map(object => {console.log(object.id)}) 

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

相关问题 我们如何从具有名称 ID 但具有特定父对象的 JSON 中获取所有属性值 - How do we get all property values from a JSON with name ID but has a specific parent object 如何从异步函数中获取数组的所有值 - How do I get all the values of an array from an async function 如何从此JSON对象获取国家/地区数组? - How do I get an array of countries from this JSON object? 如何从对象中获取键和值并返回数组? - How do I get they keys and the values from the object and return an array? 如何从 Javascript 中的嵌套对象获取值数组 - How do I get array of values from a nested object in Javascript 如何在javascript json数组对象中获取相同id的不同值 - How to get same id different values in javascript json array object 如何为我的react组件按ID过滤数据列表以获取对象的名称 - How do I filter a list of data by id for my react component to get the name of the object JSON返回多列,但所有值均作为单个字符串。 如何从数组中获取匹配的键值? - JSON returning multiple columns, but all values as single string. How do I get matching key-value from array? 如何从JSON数据获取位置名称 - How can I get Location name from JSON Data 如果hashMap具有相同的键名,如何获取对象数组中的所有值 - How do I get all values in array of objects if hashMap has same key name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM