From d81f24748874c32ea2c9d4682dc1a99ed8a563a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Tue, 25 May 2021 14:06:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BF=BB=E9=A1=B5=E5=90=8E?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E4=B8=BA1=E8=BD=ACjsonArray=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fangjia/script/temp/shenjian/Temp.groovy | 16 ++-- .../fangjia/script/temp/shenjian/poi/poi.json | 84 +++++++++++-------- .../temp/shenjian/util/GaoDeUtils.groovy | 9 +- 3 files changed, 60 insertions(+), 49 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/Temp.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/Temp.groovy index 8c42ab478..8311e3e15 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/Temp.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/Temp.groovy @@ -1,6 +1,9 @@ package com.fangjia.script.temp.shenjian +import com.alibaba.fastjson.JSONArray +import com.alibaba.fastjson.JSONObject import com.fangjia.script.lixue.util.DBUtils +import com.fangjia.script.statistics.poi.AmapPoi import com.mongodb.BasicDBObject import com.mongodb.DBObject @@ -10,15 +13,10 @@ import com.mongodb.DBObject class Temp { static void main(String[] args) { - DBObject query = new BasicDBObject() - query.put("city", "重庆") - query.put("region", "北碚") - query.put("cat", "district") - query.put("visible", 0) - query.put("name", "人民村") - DBUtils.seaweed.find(query).limit(1).each { obj -> - println(obj) - } + String jsonStr = "[{\"id\":\"B0FFLCY016\",\"parent\":[],\"childtype\":[],\"name\":\"杭州馨悦坊公寓\",\"type\":\"住宿服务;住宿服务相关;住宿服务相关\",\"typecode\":\"100000\",\"biz_type\":\"hotel\",\"address\":\"18号大街伊萨卡浩泽园\",\"location\":\"120.383947,30.289931\",\"tel\":[],\"pname\":\"浙江省\",\"cityname\":\"杭州市\",\"adname\":\"钱塘区\",\"importance\":[],\"shopid\":[],\"shopinfo\":\"0\",\"poiweight\":[],\"distance\":\"992\",\"biz_ext\":{\"rating\":[],\"cost\":[],\"hotel_ordering\":\"0\",\"lowest_price\":[],\"star\":[],\"open_time\":[],\"opentime2\":[]},\"photos\":[{\"title\":\"Logo\",\"url\":\"http://store.is.autonavi.com/showpic/7e9c5bdeeba929eb4742102b7c9bd47c\",\"provider\":[]},{\"title\":\"客房\",\"url\":\"http://store.is.autonavi.com/showpic/e4e5771e4de5083877931fda2e360f74\",\"provider\":[]},{\"title\":[],\"url\":\"http://store.is.autonavi.com/showpic/5401e1e105bcbacf550896c7575ee315\",\"provider\":[]}]}]" + JSONArray jsonArray = JSONObject.parseArray(jsonStr) + List ret = JSONObject.parseArray(jsonArray.toJSONString(), AmapPoi.class); + print(ret.size()) } // 万友七季城C区 经度纬度不同106.569161 29.498502 原始106.56881 29.50058 距离231.7003米 diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/poi.json b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/poi.json index 4777a3761..2cc6544cd 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/poi.json +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/poi.json @@ -1,38 +1,48 @@ -{ - "id": "B0FFF9RJ2O", - "parent": [], - "childtype": [], - "name": "丁兰广场", - "type": "购物服务;商场;购物中心", - "typecode": "060101", - "biz_type": [], - "address": "惠兰雅路与明珠街交汇处东北角", - "location": "120.231368,30.353127", - "tel": "0571-88111223", - "pname": "浙江省", - "cityname": "杭州市", - "adname": "上城区", - "importance": [], - "shopid": [], - "shopinfo": "0", - "poiweight": [], - "distance": "37", - "biz_ext": { - "rating": [], - "cost": "13953.00" - }, - "photos": [ - { - "title": [], - "url": "http://store.is.autonavi.com/showpic/f5dcc118938358031b45dea7e04faf45" +[ + { + "id": "B0FFLCY016", + "parent": [], + "childtype": [], + "name": "杭州馨悦坊公寓", + "type": "住宿服务;住宿服务相关;住宿服务相关", + "typecode": "100000", + "biz_type": "hotel", + "address": "18号大街伊萨卡浩泽园", + "location": "120.383947,30.289931", + "tel": [], + "pname": "浙江省", + "cityname": "杭州市", + "adname": "钱塘区", + "importance": [], + "shopid": [], + "shopinfo": "0", + "poiweight": [], + "distance": "992", + "biz_ext": { + "rating": [], + "cost": [], + "hotel_ordering": "0", + "lowest_price": [], + "star": [], + "open_time": [], + "opentime2": [] }, - { - "title": [], - "url": "http://store.is.autonavi.com/showpic/9a0fd6ceec63e030eac3ee14055206b5" - }, - { - "title": [], - "url": "http://store.is.autonavi.com/showpic/d9d2a87de3f00294665a2caeb3ee226f" - } - ] -} \ No newline at end of file + "photos": [ + { + "title": "Logo", + "url": "http://store.is.autonavi.com/showpic/7e9c5bdeeba929eb4742102b7c9bd47c", + "provider": [] + }, + { + "title": "客房", + "url": "http://store.is.autonavi.com/showpic/e4e5771e4de5083877931fda2e360f74", + "provider": [] + }, + { + "title": [], + "url": "http://store.is.autonavi.com/showpic/5401e1e105bcbacf550896c7575ee315", + "provider": [] + } + ] + } +] \ No newline at end of file diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy index f772c3ab8..9f277a4b2 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy @@ -129,9 +129,12 @@ class GaoDeUtils { } if (json && json.info && json.info == "OK") { count = json.getString("count").toInteger() - JSONArray jsonArray = json.pois - List ret = JSONObject.parseArray(jsonArray.toJSONString(), AmapPoi.class); - result.addAll(ret) + try { + List ret = JSONObject.parseArray(json.pois.toString(), AmapPoi.class) + result.addAll(ret) + } catch(Exception ex) { + ex.printStackTrace() + } } else if (json && json.infocode && json.infocode == 10003) { throw new RuntimeException("开发者的日访问量超限,被系统自动封停,第二天0:00会自动解封") } else if (json && json.infocode && json.infocode == 10004) {