Json extract and use data (node.js)

前端 未结 5 1002
南方客
南方客 2021-01-20 01:56

How can I access this data?

Here is my Json:

 {
  \"6a768d67-82fb-4dd9-9433-d83dbd2f1b78\": {
    \"name\": \"Bahut\",
    \"11\": {
      \"timestam         


        
5条回答
  •  旧巷少年郎
    2021-01-20 02:04

    You could use Object.keys to get an array of properties.

    var js = JSON.parse(json);
    var props = Object.keys(js);
    
    var result = props.map(function(prop) {
      return {
        id: prop,
        name: js[prop].name;
      };
    });
    

    The final result is an array of objects with 2 properties: id, name

提交回复
热议问题