android获取没有数组的json对象

时间:2013-12-08 13:41:44

标签: php android json

如何在android中获取没有数组的JSON对象?

   {"advertisementid":"1","advertisment_imei_id":"1","advertisment_date":"18-11-2013 11:04:48","advertisment_title":"Test","advertisment_content":"Welcome","advertisment_image":"Water lilies.jpg","advertisment_video":"funnysarda_ieC8LUbm.mp4","imei":"Test123"}

1 个答案:

答案 0 :(得分:0)

使用gson库。

对象示例

class BagOfPrimitives {
  private int value1 = 1;
  private String value2 = "abc";
  private transient int value3 = 3;
  BagOfPrimitives() {
    // no-args constructor
  }
}

(Serialization)
BagOfPrimitives obj = new BagOfPrimitives();
Gson gson = new Gson();
String json = gson.toJson(obj);  

(DeSerialization) BagOfPrimitives obj2 = gson.fromJson(json, BagOfPrimitives.class);