问一个json数据结构问题 java的 5C

{
"file":"flash_lz.png",
"frames":{
"cghb_jxyx":{
"x":1764,
"y":874,
"w":243,
"h":134,
"offX":0,
"offY":0,
"sourceW":243,
"sourceH":134
}
}
}

这是由什么类型嵌套组成

0

47个回答

基本模型{["",""]}

{
"":""
"":{["":""]}
"":{["":{"":"","":"","",""}]}
"":{["":{"":"","":"",{["":""]},""}]}
}
反正就是这样
整体对象用JSONArray接收
具体的对象用JSONObject对象接收

 JSONArray arr = new JSONArray("");
 JSONObject obj = arr.getObject("file");//可以直接获取到对应的值
 嵌套的话就是多几层解析而已

0
package demo;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class App {

    private String file;
    private Map<String,Demo> frames;

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public Map<String, Demo> getFrames() {
        return frames;
    }

    public void setFrames(Map<String, Demo> frames) {
        this.frames = frames;
    }

    @Override
    public String toString() {
        return "App{" +
                "file='" + file + '\'' +
                ", frames=" + frames +
                '}';
    }

    static class Demo {
        private String x;
        private String y;
        private String w;
        private String h;
        private String offx;
        private String offy;
        private String sourceW;
        private String sourceH;

        public String getX() {
            return x;
        }

        public void setX(String x) {
            this.x = x;
        }

        public String getY() {
            return y;
        }

        public void setY(String y) {
            this.y = y;
        }

        public String getW() {
            return w;
        }

        public void setW(String w) {
            this.w = w;
        }

        public String getH() {
            return h;
        }

        public void setH(String h) {
            this.h = h;
        }

        public String getOffx() {
            return offx;
        }

        public void setOffx(String offx) {
            this.offx = offx;
        }

        public String getOffy() {
            return offy;
        }

        public void setOffy(String offy) {
            this.offy = offy;
        }

        public String getSourceW() {
            return sourceW;
        }

        public void setSourceW(String sourceW) {
            this.sourceW = sourceW;
        }

        public String getSourceH() {
            return sourceH;
        }

        public void setSourceH(String sourceH) {
            this.sourceH = sourceH;
        }

        public Demo(String x, String y, String w, String h, String offx, String offy, String sourceW, String sourceH) {
            this.x = x;
            this.y = y;
            this.w = w;
            this.h = h;
            this.offx = offx;
            this.offy = offy;
            this.sourceW = sourceW;
            this.sourceH = sourceH;
        }

        @Override
        public String toString() {
            return "Demo{" +
                    "x='" + x + '\'' +
                    ", y='" + y + '\'' +
                    ", w='" + w + '\'' +
                    ", h='" + h + '\'' +
                    ", offx='" + offx + '\'' +
                    ", offy='" + offy + '\'' +
                    ", sourceW='" + sourceW + '\'' +
                    ", sourceH='" + sourceH + '\'' +
                    '}';
        }
    }

    public static void main(String args[]) {

        App a = new App();
        Demo d = new Demo("1764", "874", "243", "134", "0", "0", "243", "134");
        Map<String, Demo> paramMap = new HashMap<>();
        paramMap.put("cghb_jxyx", d);
        a.setFile("flash_lz.png");
        a.setFrames(paramMap);
        System.out.println(JSONObject.toJSONString(a));
    }

}


输出结果:
{"file":"flash_lz.png","frames":{"cghb_jxyx":{"h":"134","offx":"0","offy":"0","sourceH":"134","sourceW":"243","w":"243","x":"1764","y":"874"}}}

0

Object{
Object{
Object{
}
}
}

0

该实体封装为 两个属性 一个是 private String file; private frames f(实体属性);

0

可以说是Object 的嵌套 如果你是开发Android 的话 一个bean 就可以搞定了

0

这个应该是 Object{String,Map{Object{}}}

0

"cghb_jxyx":{
"x":1764,
"y":874,
"w":243,
"h":134,
"offX":0,
"offY":0,
"sourceW":243,
"sourceH":134
}是frames对象的一个属性
file也是一个对象,和frames同级

0

var json = {"file":"flash_lz.png","frames":{"cghb_jxyx":{"x":1764,"y":874,"w":243,"h":134,"offX":0,"offY":0,"sourceW":243,"sourceH":134}}};
var file = json.file;
var frames = json.frames;
var cghb_jxyx = frames.cghb_jxyx;
var x = cghb_jxyx.x;
var y = cghb_jxyx.y;
........

0

https://www.bejson.com/json2javapojo/new/

去这输入一下就知道了.

0

就是基本的对象 只是多层嵌套而已 你可以一层一层的看

0
共47条数据 首页 1 3 5 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!