简体   繁体   中英

How do I shape the returned JSON object into array in Javascript/JQUery?

I am getting the JSON object from an API in this format:

[{"Id":1,"Name":"A","ParentId":0},
{"Id":2,"Name":"B","ParentId":1},
{"Id":3,"Name":"C","ParentId":2}]

I want to convert it into this format

['Mike', null, 'The President'],
          ['Alice', 'Mike', null],
          ['Bob', 'Jim', 'Bob Sponge'],
          ['Carol', 'Bob', null]

So I can pass it to a function in google api like this

var data = google.visualization.arrayToDataTable(<<DATA>>);

How do I do that? Any advice?

You're probably not expecting to get 'Mike' from 'Id', so how this is supposed to work is a little hard to understand, and I'm not sure I really get the question, but did you try:

var myData = $​.makeArray(myObject)​;

jQuery makeArray()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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