utopiaZhangXiaoXin 2016-06-16 01:46 采纳率: 33.3%
浏览 2981

fastJSON解析遇到属性名是数字的怎么办

JSON字符串
{
"error_code": 0,
"reason": "success",
"result": {
"1": "A或者正确",
"10": "BC",
"11": "BD",
"12": "CD",
"13": "ABC",
"14": "ABD",
"15": "ACD",
"16": "BCD",
"17": "ABCD",
"2": "B或者错误",
"3": "C",
"4": "D",
"7": "AB",
"8": "AC",
"9": "AD"
}
}
我不可能建出如下类,也就不能使用fastJSON解析
private String 1;

private String 10;

private String 11;

private String 12;

private String 13;

private String 14;

private String 15;

private String 16;

private String 17;

private String 2;

private String 3;

private String 4;

private String 7;

private String 8;

private String 9;

public void set1(String 1){
this.1 = 1;
}
public String get1(){
return this.1;
}
public void set10(String 10){
this.10 = 10;
}
public String get10(){
return this.10;
}
public void set11(String 11){
this.11 = 11;
}
public String get11(){
return this.11;
}
public void set12(String 12){
this.12 = 12;
}
public String get12(){
return this.12;
}
public void set13(String 13){
this.13 = 13;
}
public String get13(){
return this.13;
}
public void set14(String 14){
this.14 = 14;
}
public String get14(){
return this.14;
}
public void set15(String 15){
this.15 = 15;
}
public String get15(){
return this.15;
}
public void set16(String 16){
this.16 = 16;
}
public String get16(){
return this.16;
}
public void set17(String 17){
this.17 = 17;
}
public String get17(){
return this.17;
}
public void set2(String 2){
this.2 = 2;
}
public String get2(){
return this.2;
}
public void set3(String 3){
this.3 = 3;
}
public String get3(){
return this.3;
}
public void set4(String 4){
this.4 = 4;
}
public String get4(){
return this.4;
}
public void set7(String 7){
this.7 = 7;
}
public String get7(){
return this.7;
}
public void set8(String 8){
this.8 = 8;
}
public String get8(){
return this.8;
}
public void set9(String 9){
this.9 = 9;
}
public String get9(){
return this.9;
}

}
这样肯定报错啊
求大神解答

  • 写回答

5条回答 默认 最新

  • lzj0327 2016-06-16 02:00
    关注
     String str = "{\"error_code\": 0,"+
                "\"reason\": \"success\","+
                "\"result\": {"+
                "\"1\": \"A或者正确\","+
                "\"10\": \"BC\","+
                "\"11\": \"BD\","+
                "\"12\": \"CD\","+
                "\"13\": \"ABC\","+
                "\"14\": \"ABD\","+
                "\"15\": \"ACD\","+
                "\"16\": \"BCD\","+
                "\"17\": \"ABCD\","+
                "\"2\": \"B或者错误\","+
                "\"3\": \"C\","+
                "\"4\": \"D\","+
                "\"7\": \"AB\","+
                "\"8\": \"AC\","+
                "\"9\": \"AD\"}}";
            JSONObject obj = JSONObject.parseObject(str);
            String result = obj.getString("result");
            JSONObject obj1 = JSONObject.parseObject(result);
            System.out.println(obj1.getString("1"));这不是很正常吗,你那边怎么写的?
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果