简体   繁体   English

如何在Javascript / JQUery中将返回的JSON对象整形为数组?

[英]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)​;

jQuery makeArray() jQuery makeArray()

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

相关问题 Javascript-一个未知的JSON对象返回给我,我怎么看? - Javascript - A unknown JSON object was returned to me, how do I look at it? 如何在jQuery中将JSON字符串转换为JavaScript对象? - How do I convert a JSON string to a JavaScript object in jQuery? 我如何在运行时使用jquery创建json对象数组? - How do i create array of json object at runtime using jquery? 如何将多维JSON对象转换为JavaScript数组 - How do I convert a multi dimensional JSON object into javascript array 如何访问这个 Javascript 数组(JSON object?)? - How do I access this Javascript array (JSON object?)? 如何使用javascript从JSON返回的对象中提取特定值? - How do I extract a specific value from a JSON returned object with javascript? 如何使用 jQuery Ajax 成功在我的 html 上打印邮递员返回的 JSON 数组? - How do I print my postman returned JSON array on my html using jQuery Ajax success? 如何在返回 json 请求的 api 请求的阵列中拉出嵌套的 object? - How do I pull a nested object out of an array with an api request returned json? 如何将函数返回的数组复制到 JavaScript 中的另一个数组中? - How do I copy an array returned by a function into another array in JavaScript? 我如何从带有 javascript 的表单返回 json? - how do i get json returned from a form with javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM