包装JSON对象或更改JSON格式

时间:2014-04-27 06:41:42

标签: json

##我是Javascript和JSON的新手。我需要转换像这样的数据数组:

{
    "名称":"明尼苏达大学扩展",
    "日期时间":" 1914-00-00T00:00:00&#34 ;,
    "纬度":44.982515,
    "经度": - 93.17489,
    "大小":2
  }

##对此:

{
      "几何" :{
         "类型":"点&#34 ;,
         "坐标":[
             44.982515,
             -93.17489
                        ]              },
       "键入":"功能",
            "属性":{
                "尺寸":2,
                " datetime":" 1914-00-00T00:00:00"
              }       }

我完全不知道如何传输数据格式,请帮忙!

1 个答案:

答案 0 :(得分:2)

使用类似的东西:

records = `your original list`
newrecords = []


for (var i=0; i<records.length;i++)
{ 
    var newrecord = {
    "geometry" : {
    "type":"Point",
      "coordinates": [records[i].Latitude,records[i].Longitude] 
    },
    "type": "Feature",
    "properties": {
      "size": records[i].size,
      "datetime": records[i].datetime
    } 
  }

  newrecords.push(newrecord)

}