search

Home  >  Q&A  >  body text

python如何搜索字符串

想在一个string里面查找一些关键字及其后面的一些数据,应该怎么做?比如:

{
    "status": "1", 
    "count": "612", 
    "info": "OK", 
    "infocode": "10000", 
    "suggestion": {
        "keywords": [ ], 
        "cities": [ ]
    }, 
    "pois": [
        {
            "id": "B001C7WEYU", 
            "name": "天府广场", 
            "type": "风景名胜;公园广场;城市广场", 
            "typecode": "110105", 
            "biz_type": "tour", 
            "address": "人民南路一段86号", 
            "location": "104.065837,30.657349", 
            "tel": "028-86203702", 
            "distance": [ ], 
            "biz_ext": [ ], 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "青羊区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "2", 
            "poiweight": [ ]
        }, 
        {
            "id": "BV10069526", 
            "name": "天府广场(地铁站)", 
            "type": "交通设施服务;地铁站;地铁站", 
            "typecode": "150500", 
            "biz_type": [ ], 
            "address": "1号线;2号线", 
            "location": "104.065751,30.657453", 
            "tel": [ ], 
            "distance": [ ], 
            "biz_ext": [ ], 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "青羊区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "2", 
            "poiweight": [ ]
        }, 
        {
            "id": "B0FFH33FVA", 
            "name": "天府广场(西入口)", 
            "type": "通行设施;虚拟门;虚拟门", 
            "typecode": "991500", 
            "biz_type": [ ], 
            "address": [ ], 
            "location": "104.064305,30.657470", 
            "tel": [ ], 
            "distance": [ ], 
            "biz_ext": [ ], 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "青羊区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "2", 
            "poiweight": [ ]
        }, 
        {
            "id": "B0FFH0MTQL", 
            "name": "天府广场(西南入口)", 
            "type": "通行设施;虚拟门;虚拟门", 
            "typecode": "991500", 
            "biz_type": [ ], 
            "address": [ ], 
            "location": "104.064564,30.656504", 
            "tel": [ ], 
            "distance": [ ], 
            "biz_ext": [ ], 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "青羊区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "2", 
            "poiweight": [ ]
        }, 
        {
            "id": "B0FFH0NE2D", 
            "name": "天府广场(东南入口)", 
            "type": "通行设施;虚拟门;虚拟门", 
            "typecode": "991500", 
            "biz_type": [ ], 
            "address": [ ], 
            "location": "104.066796,30.656457", 
            "tel": [ ], 
            "distance": [ ], 
            "biz_ext": [ ], 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "青羊区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "2", 
            "poiweight": [ ]
        }, 
        {
            "id": "B0FFFEX5CW", 
            "name": "天府广场-停车场", 
            "type": "交通设施服务;停车场;公共停车场", 
            "typecode": "150904", 
            "biz_type": [ ], 
            "address": [ ], 
            "location": "104.065585,30.657674", 
            "tel": [ ], 
            "distance": [ ], 
            "biz_ext": [ ], 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "青羊区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "2", 
            "poiweight": [ ]
        }, 
        {
            "id": "B001C7X7HB", 
            "name": "成都天府广场停车场", 
            "type": "交通设施服务;停车场;公共停车场", 
            "typecode": "150904", 
            "biz_type": [ ], 
            "address": "人民东路天府广场B2层", 
            "location": "104.064416,30.657384", 
            "tel": [ ], 
            "distance": [ ], 
            "biz_ext": [ ], 
            "parking_type": "地下", 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "青羊区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "2", 
            "poiweight": [ ]
        }, 
        {
            "id": "BV10061425", 
            "name": "天府广场东站(公交站)", 
            "type": "交通设施服务;公交车站;公交车站相关", 
            "typecode": "150700", 
            "biz_type": [ ], 
            "address": "16路;45路;53路;61路;64路;机场专线2号线", 
            "location": "104.067451,30.657734", 
            "tel": [ ], 
            "distance": [ ], 
            "biz_ext": [ ], 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "青羊区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "2", 
            "poiweight": [ ]
        }, 
        {
            "id": "B001C7ZW67", 
            "name": "汉庭酒店(成都天府广场东店)", 
            "type": "住宿服务;宾馆酒店;经济型连锁酒店", 
            "typecode": "100105", 
            "biz_type": "hotel", 
            "address": "东华正街28号", 
            "location": "104.069618,30.660137", 
            "tel": "028-86620055", 
            "distance": [ ], 
            "biz_ext": [ ], 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "锦江区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "0", 
            "poiweight": [ ]
        }, 
        {
            "id": "BX10013955", 
            "name": "天府广场地铁站B口", 
            "type": "交通设施服务;地铁站;出入口", 
            "typecode": "150501", 
            "biz_type": [ ], 
            "address": "1号线;2号线", 
            "location": "104.066339,30.657578", 
            "tel": [ ], 
            "distance": [ ], 
            "biz_ext": [ ], 
            "pname": "四川省", 
            "cityname": "成都市", 
            "adname": "青羊区", 
            "importance": [ ], 
            "shopid": [ ], 
            "shopinfo": "2", 
            "poiweight": [ ]
        }
    ]
}

这里随便举了个例子,我想要‘location’和后面的数字,但不要其他的字符(包括‘location’)应该怎么做?

阿神阿神2785 days ago492

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:29:58

    From the format point of view, this looks like a json. You can read this string into a variable, for example

    import json
    
    with open('test.json','r') as f:
        vContact=json.load(f)
        for i in vContact['pois']:
            print(i['location'])

    I got the location data you want. I don’t know if I understand it correctly

    reply
    0
  • Cancelreply