gson - How to use json parese this content -


i got json string this,

{     "resultcode": 200,     "operation": 0,     "resultmsg": "正常初始化",     "debugmsg": "",     "resultcount": 3,     "result": {         "operation": 0,         "verify_key": "6f3e9169e4fcfbe4a52606c013348650",         "user_id": 41201     } } 

but want convert to,

public class clientresult {     string result;     string resultmsg;     string debugmsg;     int resultcode;     int operation; } 

.if use gson.fromjson(result, clientresult.class),get exception

com.google.gson.jsonsyntaxexception: java.lang.illegalstateexception: expected string begin_object @ line 1 column 118

i want parse string, not object, because result field of clientresut not same,it maybe array sometimes. result

 {     "resultcode": 200,     "operation": 0,     "resultmsg": "",     "debugmsg": "",     "resultcount": 12,     "result": {       "id": "4392",       "pm25": "44",       "time": "1433403001",       "l_temperature": "9",       "h_temperature": "20",       "c_temperature": "14",       "weather_icon": "http://60.31.215.212/zsgj/public/weather/zhenyu.png",       "tm_l_temperature": "8",       "tm_h_temperature": "25",     }   }

so want parse string..

its because doing wrong, "result" json object in json, can go approach of creating 2 pojos json can use in gson.

public class result {     private string operation;      private string verify_key;      private string user_id;  } 

and original class

public class clientresult {      private string resultmsg;      private result result;      private string debugmsg;      private string operation;      private string resultcount;  private string resultcode; 

}


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -