android如何从json字符串中取自己想要的数据
程序员文章站
2024-02-24 10:37:28
...
场景
假设后台返回的json数据是以字符串的形式 需要自己处理才能拿到自己想要的数据
如
{
"code":2000,
"msg":"success",
"requestDomain":"oil.htinno.com",
"data":"{"station_id":6002,"link":"https:\/\/my.htinno.com\/#\/pages\/home\/home?
key=03c075eebc68da05cd618c163ef9a2a3",
"key":"03c075eebc68da05cd618c163ef9a2a3","expire_time":1609991942}"
}
可以看到data里的数据是一个字符串"{"station_id":6002,"link":"https:\/\/my.htinno.com\/#\/pages\/home\/home?key=03c075eebc68da05cd618c163ef9a2a3","key":"03c075eebc68da05cd618c163ef9a2a3","expire_time":1609991942}"
假如想要link里的数据 怎么办呢?
JSONObject jsonObject = new JSONObject(model.getData());
String link = jsonObject.getString("link");