如何为List< Class name>创建JSONArray; [英] How to Create JSONArray for a List<Class name>
本文介绍了如何为List< Class name>创建JSONArray;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一堂课
class Student {
String name;
String age;
}
我有一个返回
public List<Student> getList(){
List<Student> li =new ArrayList();
....
li.add(new Student('aaa','12'));
...
return li;
}
我需要像这样将列表转换成JSONArray
I need to convert that list into JSONArray like this
[{"name":"sam","age":"12"},{"name":"sri","age":"5"}]
有人可以帮我得到这个吗?在此先感谢.
Can anyone help me to get this? Thanks in Advancee..
推荐答案
我认为您无需下载Jettison jar文件.
I think you need not download the jettison jar file.
使用JSONArray
和JSONObject
,您可以轻松地将该列表转换为JSON对象,例如@Juniad答案
Using JSONArray
and JSONObject
you can easily convert that list into JSON object like @Juniad answer
这篇关于如何为List< Class name>创建JSONArray;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文