json解析出来的数据为null

曹逗逗 发布于 2016/09/18 10:48
阅读 329
收藏 0

{
      "Result":[
          {
              "TradeAccountCode":"100000001",
              "TradeAccount":"201601",
              "NAME":"测试1"
          }
      ]
  }我想解析出来之后得到TradeAccountCode这个值,然后我解析出来的是空,我的代码:


   Gson gson = new Gson();//new一个Gson对象
   Fragment_login fragment_login = new Fragment_login();
   fragment_login = gson.fromJson(json, Fragment_login.class);
   TradeAccountCode=fragment_login.getTradeAccountCode();  
   System.out.println("TradeAccountCode                                "+TradeAccountCode);

Fragment_login.class


public class Fragment_login {
 //{"Result":[{"TradeAccountCode":"100000001","TradeAccount":"201601","NAME":"测试1"}]}
 private static String TradeAccountCode;
 private static String TradeAccount;
 private static String NAME;
 public Fragment_login()
 {}
 public Fragment_login(String TradeAccountCode,String TradeAccount,String NAME )
 {
  super();
  this.TradeAccountCode=TradeAccountCode;
  this.TradeAccount=TradeAccount;
  this.NAME=NAME;
 }
 public String getTradeAccountCode()
 {
  return TradeAccountCode;
 }
 public void setTradeAccountCode(String TradeAccountCode)
 {
  this.TradeAccountCode = TradeAccountCode;
 }
 public String getTradeAccount()
 {
  return TradeAccount;
 }
 public void setTradeAccount(String TradeAccount)
 {
  this.TradeAccount = TradeAccount;
 }
 public String getNAME()
 {
  return NAME;
 }
 public void setNAME(String NAME)
 {
  this.NAME=NAME;
 }
 @Override 
    public String toString() { 
        return "Result [TradeAccountCode=" + TradeAccountCode + ", TradeAccount=" + TradeAccount + ", NAME=" + NAME 
                 + "]"; 
    }
}

加载中
0
So丶Love
So丶Love
你的实体对象不对
0
mark35
mark35
js,php都不是问题,两行代码分分钟解决
0
lindent
lindent
Fragment_login 里面弄个 Result 对象,Result 对象有  TradeAccountCode;TradeAccount;NAME;这三个属性,这样就能解析出来
返回顶部
顶部