#json转对象方法
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import net.sf.json.xml.XMLSerializer;
String endString="";
//发送请求返回map数组的string字符串
String result = HttpClient.httpPost(XXX);
XMLSerializer xmlSerializer = new XMLSerializer();
String resultStr = xmlSerializer.read(result).toString();
//根据自己的逻辑拼装json串(我这里是按照自己的逻辑)
JSONObject objectStr = JSON.parseObject(resultStr);
JSONObject temp;
JSONObject alipayJson = new JSONObject();
temp = objectStr.getJSONObject("response");
if (temp != null){
alipayJson = temp.getJSONObject("alipay");
}
alipayJson.put("is_success",objectStr.getString("is_success"));
alipayJson.put("error",objectStr.getString("error"));
//json转对象(jsonh和对象里面的字段对上即可)
yourbean response=JSON.parseObject(alipayJson.toJSONString(),new TypeReference<yourbean>(){});
之前在网上也搜索了很多帖子 但是用起来 都是要饮用两中jar包的json 用起来太麻烦,后来找到这种,个人认为还是比较简单的写起来。