[英]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: 我从API获取JSON对象,格式如下:
[{"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 所以我可以像这样将其传递给google api中的函数
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: 您可能不希望从'Id'中获得'Mike',所以这应该如何工作有点难以理解,我不确定我是否真的得到了这个问题,但是您是否尝试过:
var myData = $.makeArray(myObject);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.