implementation 'com.alibaba:fastjson:1.2.72'
<uses-permission android:name="android.permission.INTERNET" />
import com.alibaba.fastjson.JSON;
// JSON字符串轉換為對象
String jsonString = "{\"name\":\"John\", \"age\":30}";
User user = JSON.parseObject(jsonString, User.class);
// 對象轉換為JSON字符串
User user = new User("John", 30);
String jsonString = JSON.toJSONString(user);
-keep class com.alibaba.fastjson.** { *; }
JSON.DEFAULT_PARSER_FEATURE = JSON.DEFAULT_PARSER_FEATURE | Feature.SupportAutoType.mask;
JSON.DEFAULT_GENERATE_FEATURE = JSON.DEFAULT_GENERATE_FEATURE | Feature.SupportAutoType.mask;
以上是集成fastjson庫到Android項目中的基本步驟,根據實際需求可以進一步優化和定制。