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

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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记