javascript 将JSON数据映射到JavaScript中的类/对象

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 将JSON数据映射到JavaScript中的类/对象相关的知识,希望对你有一定的参考价值。


// Example 1
// *requires you to have the same properties in your object and your JSON object.

var fra = {
	"ipda": 6786868,
	"eventType": 1,
	"description": "Recogido",
	"lat": 39.4699075,
	"lon": -0.3762881
};

function fru(ipda, eventType, description, lat, lon) {
    this.ipda = ipda;
    this.eventType = eventType;
    this.description = description;
    this.other = "Fixed value";
    this.coordinates = [lon, lat];
    this.kk1 = lon; // undefined por que?
    this.kk2 = lat; // undefined por que?
}

var fro = $.extend(new fru(), fra);

console.log(fro);

以上是关于javascript 将JSON数据映射到JavaScript中的类/对象的主要内容,如果未能解决你的问题,请参考以下文章