gson
1.下载gson-2.3.1.jar , 放到项目libs里
2.对象转json字符串
Gson gson=new Gson();
String senddatastr=gson.toJson(obj);
3.json字符串转对象
Gson gson=new Gson();
return gson.fromJson(packetContent.toString(),PackageCls.class);
可以对返回结果再强制转换一次
JAVA使用genson
genson
Genson genson =
new
Genson();
String json = genson.serialize(
777.777
);
// the output will be 777.777
genson.serialize(
true
);
// output is true (without quotes)
genson.deserialize(
"777"
,
int
.
class
);
// deserializes it into 777
genson.deserialize(
"777.777"
, Object.
class
);
// will return 777.777 (a double)
genson.deserialize(
"null"
, Object.
class
);
// will return null;