Parsing array inside object with unknown key and unknown values

Halloyo

I have the following JSON (snippet):

"1": {
  "Name": [
    "Person1",
    "Person2",
    "Person3",
    "Person4",
    "Person5"
  ]
}
"4"{
  "Name": [
    "AnotherPerson1",
    "AnotherPerson2",
    "AnotherPerson3",
    "AnotherPerson4",
    "AnotherPerson5"
  ]
}
...

I don't know the key value (it doesn't increase linearly) and I don't know the different values inside "Name" (only that they are inside "Name", are strings, and total 5).

I want to return all first strings under "Name" and their respective root(?) key. So "Person1" & "1"; "AnotherPerson1" & "4", etc.

I've only managed to make it work when I know the key value but it's too long to write.

console.log(data[1]["Name"][1]);
p1100i
var keys = Object.keys(data);

keys.forEach(function(key) {
  console.log(data[key].Name[0], 'on root key', key);
});

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

PHP - Get all values with specific array key from multidimensional array with unknown depth

分類Dev

Traverse JSON Object in Javascript with unknown key

分類Dev

How to loop over object with unknown keys and values

分類Dev

Unknown SQLCODE values

分類Dev

Parsing JSON Object inside Array in Jackson

分類Dev

Downcast object to unknown class

分類Dev

Storing an array of unknown length

分類Dev

Reduce the array of object by object key and sum the values

分類Dev

Jackson: ignore unknown enum values

分類Dev

Is it safe to swap values of an unknown type

分類Dev

Gson parsing of multiple arrays with unknown fields

分類Dev

SwiftUI Unknown Attribute 'Observable Object'

分類Dev

Check existence of unknown field in array

分類Dev

How to decrypt AES with an unknown KEY and IV in Java?

分類Dev

Django - how to make OR query for unknown number of values

分類Dev

Unknown template object error with handlebars 2.0 runtime

分類Dev

Is there a test to see if unknown object is of a value type?

分類Dev

Javascript: Determine unknown array length and map dynamically

分類Dev

I am trying to push values from an object inside an array

分類Dev

Array inside array to Object

分類Dev

How can I convert this object to an array and access values by key in React?

分類Dev

How to get the count of repeated key values of array object of consecutive elements?

分類Dev

How to create key => values array in a collection object in Javascript

分類Dev

Unknown variable +

分類Dev

Unknown NullPointerException

分類Dev

It is possible to create a generic search method where key is unknown

分類Dev

ElasticSearch 6.2-aggs return:unknown_named_object_exception

分類Dev

typescript compile error with unknown google.maps object type

分類Dev

javascript array of object with key

Related 関連記事

  1. 1

    PHP - Get all values with specific array key from multidimensional array with unknown depth

  2. 2

    Traverse JSON Object in Javascript with unknown key

  3. 3

    How to loop over object with unknown keys and values

  4. 4

    Unknown SQLCODE values

  5. 5

    Parsing JSON Object inside Array in Jackson

  6. 6

    Downcast object to unknown class

  7. 7

    Storing an array of unknown length

  8. 8

    Reduce the array of object by object key and sum the values

  9. 9

    Jackson: ignore unknown enum values

  10. 10

    Is it safe to swap values of an unknown type

  11. 11

    Gson parsing of multiple arrays with unknown fields

  12. 12

    SwiftUI Unknown Attribute 'Observable Object'

  13. 13

    Check existence of unknown field in array

  14. 14

    How to decrypt AES with an unknown KEY and IV in Java?

  15. 15

    Django - how to make OR query for unknown number of values

  16. 16

    Unknown template object error with handlebars 2.0 runtime

  17. 17

    Is there a test to see if unknown object is of a value type?

  18. 18

    Javascript: Determine unknown array length and map dynamically

  19. 19

    I am trying to push values from an object inside an array

  20. 20

    Array inside array to Object

  21. 21

    How can I convert this object to an array and access values by key in React?

  22. 22

    How to get the count of repeated key values of array object of consecutive elements?

  23. 23

    How to create key => values array in a collection object in Javascript

  24. 24

    Unknown variable +

  25. 25

    Unknown NullPointerException

  26. 26

    It is possible to create a generic search method where key is unknown

  27. 27

    ElasticSearch 6.2-aggs return:unknown_named_object_exception

  28. 28

    typescript compile error with unknown google.maps object type

  29. 29

    javascript array of object with key

ホットタグ

アーカイブ