简体   繁体   中英

How to convert arraylist of custom object in to json in javascript

I have a (java.util.List) List returned to the jag. That should be printed as a json .

   var storeForum = Packages.org.wso2.carbon.forum.registry.RegistryForumManager;

   var forum = new storeForum();

   var start = request.getParameter('start');
   var count = request.getParameter('count');

   var array =forum.fetchForumTopics(start,count, tenantDomainsArr, -1234, user.username);

forum.fetchForumTopics method returns

    List<customOjbect> 

How to print it as a json. Didn't find anything useful on net.

i'm not quite sure what a jag is - but you can use JSON.stringify() to convert an array of pairs or values into a JSON object

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

JSON.stringify(array) 

由于这是一个Java对象,您是否可以使用可以将相应的Object转换为JSON的Java模块尝试进行此转换?。您可能必须将该模块导入.jag(jaggery)文件。

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