嘿嘿,
我只是在构建某种地理编码器,我需要将 json-map 发送到 groovy 后端,
试图映射这个 ul 结构:http: //jsfiddle.net/PJFVN/1/
<ul id="hiddenmap">
<li class="hidden" id="street">Westerwarft 2</li>
<li class="hidden" id="plz">25859</li>
<li class="hidden" id="city">Hallig Hooge</li>
<li class="hidden" id="country" value="" >DE</li>
<li class="hidden" id="lon" > 8.516472</li>
<li class="hidden" id="lat" >54.577993</li>
</ul>
到一张看起来像的地图
[{"street":"Westerwarft 2","plz":"25859","location":{"lat":"54.577993","lon":" 8.516472"},"country":"DE"}]
使用以下 js:
var map = $('#hiddenmap').map(function() {
var $item = $(this);
var loc = '{"lat":"'+$item.find('li#lat').text()+'","lon":"'+$item.find('li#lon').text()+'"},';
return {
street: $item.find('li#street').text(),
plz: $item.find('li#plz').text(),
location:loc ,
country: $item.find('li#country').text()
};
}).get();
var v = JSON.stringify(map);
alert(v);
但正如你在小提琴中看到的那样,我的肮脏尝试抛出了
[{"street":"Westerwarft 2","plz":"25859","location":"{\"lat\":\"54.577993\",\"lon\":\" 8.516472\"},","country":"DE"}]
所以我需要一种本地方式来获取地图内的位置对象,并且从角度来看,我需要将更多地址加入地图
有没有办法这样做?
因为目前我正在重蹈覆辙,为每个看起来很糟糕的不同情况手动构建地图,例如:
var String = '['+'{'+'"fax":'+'"'+fax1+'"'+','+'"genau":'+genau1+','+'"land":'+'"'+land1+'"'+','+'"location": {'+'"lon":'+lon1+','+'"lat":'+lat1+'},'+'"notruf":'+'"'+notruf1+'"'+','+'"ort":'+'"'+ort1+'"'+','+'"plz":'+'"'+plz1+'"'+','+'"strasse":'+'"'+strasse1+'"'+','+'"telefon":'+'"'+telefon1+'"},{'+'"fax":'+'"'+fax2+'"'+','+'"genau":'+genau2+','+'"land":'+'"'+land2+'"'+','+'"location": {'+'"lon":'+lon2+','+'"lat":'+lat2+'},'+'"notruf":'+'"'+notruf2+'"'+','+'"ort":'+'"'+ort2+'"'+','+'"plz":'+'"'+plz2+'"'+','+'"strasse":'+'"'+strasse2+'"'+','+'"telefon":'+'"'+telefon2+'"}]';
我需要摆脱这个
提前感谢您的任何提示