我有一個我的類「Points」對象的數組,我想將它們放在JSONArray上,以前轉換爲JSONObject,但我遇到了一個我無法解決的問題,我無法解決把我的觀點[]放在JSONObject上,我不知道該怎麼做。我把代碼解釋得更好。將我的類投射到JSONObject
主要代碼:
JSONArray jsPoints = new JSONArray();
for(int i = 0; i < points.length; i++)
{
JSONObject js = new JSONObject(points[i]);
jsPoints.put(js);
}
Point類:
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,找到你正在尋找的最好的圖書館 –