【发布时间】:2014-05-29 11:37:22
【问题描述】:
我有一个我的类“Points”的对象数组,我想把它们放在一个 JSONArray 上,之前转换为 JSONObject,但是我有一个问题我无法解决,我不能把我的点[]在 JSONObject 上,我不知道该怎么做。我把代码解释得更好。
主要代码:
JSONArray jsPoints = new JSONArray();
for(int i = 0; i < points.length; i++)
{
JSONObject js = new JSONObject(points[i]);
jsPoints.put(js);
}
点类:
public class Point {
String _id;
String _comment;
String _calification;
String _coords;
int _X;
int _Y;
public Point(String id, String comment, String calification, String coords, int x, int y)
{
_id = id;
_comment = comment;
_calification = calification;
_coords = coords;
_X = x;
_Y = y;
}
}
将价值观引入我的班级:
private void createPoints()
{
points = new Point[drawedInterestPoints.size() / 2];
int j = 0;
for(int i = 0; i < drawedInterestPoints.size() - 1; i++)
{
if(i % 2 == 0)
{
points[j] = new Point(pointType.get(i),comments.get(i),calification.get(i),GPScoords.get(i),drawedInterestPoints.get(i),drawedInterestPoints.get(i + 1));
j++;
}
}
}
任何人都可以告诉我我必须做什么才能将我的每个点 [] 放入 JSONObject 中,然后放入 JSONArray 中?谢谢!
【问题讨论】:
-
看看 gson,很棒的库,正是你正在寻找的东西