如何访问JSON中的数据

时间:2019-05-13 08:49:48

标签: jquery json

我有一个像这样的json文件,我在执行parse

后得到
var json = JSON.parse(data)

 {"current_page":1,
"data":[{"id":1,"test_col":"Test one"},{"id":3,"test_col":"Test three"},{"id":4,"test_col":"Updated from post man"},{"id":5,"test_col":"Test five"},{"id":6,"test_col":"Test six"},{"id":7,"test_col":"Test seven"},{"id":8,"test_col":"Test eight"},{"id":9,"test_col":"Test nine"},{"id":10,"test_col":"Test ten"},{"id":11,"test_col":"test eleven"}],
"first_page_url":"http:\/\/api.changemaker\/api\/test?page=1","from":1,"last_page":2,"last_page_url":"http:\/\/api.changemaker\/api\/test?page=2","next_page_url":"http:\/\/api.changemaker\/api\/test?page=2","path":"http:\/\/api.changemaker\/api\/test","per_page":10,"prev_page_url":null,"to":10,"total":15}

我尝试这样访问它

console.log(json.data)
console.log(json.current_page)

但是我都没有定义

1 个答案:

答案 0 :(得分:0)

它的工作。请检查...


import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;

public class Vector2D {

    private DoubleProperty xProperty = new SimpleDoubleProperty(0);
    private DoubleProperty yProperty = new SimpleDoubleProperty(0);

    public Vector2D(double x, double y) {
        this.setX(x);
        this.setY(y);
    }

    public Vector2D(final Vector2D v) {
        this(v.getX(), v.getY());
    }

    public Vector2D(){this(0,0); }

    public double getX() {
        return xProperty.getValue();
    }

    public void setX(double x) {  this.xProperty.setValue(x);   }

    public double getY() {
        return yProperty.getValue();
    }

    public void setY(double y) {
        this.yProperty.setValue(y);
    }

    public void setVector(Vector2D vector2D) {
        setY(vector2D.getY());
        setX(vector2D.getX());
    }

    public DoubleProperty getXProperty() {
        return xProperty;
    }
    public DoubleProperty getYProperty() {
        return yProperty;
    }
}