简体   繁体   English

从javascript / jQuery中的第三方API序列化数据

[英]Serialize the data from 3rd party API in javascript/jQuery

I want to do a serialize the data that I got from 3rd Party API. 我想对我从3rd Party API获得的数据进行序列化。 The following Picture is what I got from the API 下图是我从API得到的图片

从Ink Filepicker API接收的数据

As you can see in the photo, I have received 2 sets of the Information which indicated by the number in the []. 如您在照片中看到的,我已经收到2套信息,这些信息由[]中的数字表示。 And when I do the POST request using jQuery, the multiple Parameters Posts to my Java method. 当我使用jQuery发出POST请求时,多个Parameters都发布到了我的Java方法中。 What I would like to do is to encapsulate each set ot the Information into a Group and after that serialize them in one parameter and sent it back as one object that hold all the things inside. 我想做的是将信息的每个集合封装到一个组中,然后将它们序列化为一个参数,然后将其作为包含所有内容的一个对象发送回去。 How can I do it by Javascrip or jQuery??? 如何通过Javascrip或jQuery做到这一点?

anyway, this is my code 无论如何,这是我的代码

function getMediaInfo(InkBlob){

console.log(InkBlob);

jQuery.ajax({
  type: 'POST',
  url: '/webapp/filepicker/importAssets',
  dataType: 'json',
  data: {"inkBlob": InkBlob}
  }); }

All I want to do is to set only one parameter call inkBlob that contains the Information as Show in the photo above. 我要做的就是只设置一个参数调用inkBlob,该参数包含如上图所示的信息。

How about - 怎么样 -

For Serializing js object
var str = JSON.stringify(InkBlob);

jQuery.ajax({
  type: 'POST',
  url: '/webapp/filepicker/importAssets',
  dataType: 'json',
  data: {"inkBlob": str}
  }); 

Note 注意

JSON.stringify is not available for older browser, use JSON2.js for older browsers. JSON.stringify不适用于较旧的浏览器,请对较旧的浏览器使用JSON2.js

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

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