如何在Python中从RESTURL读取数据并加载到列表

如何在Python中从RESTURL读取数据并加载到列表,python,Python,如果我有一个rest服务URL,你能告诉我吗 http://domain.ca/ArcGIS/rest/services/appData?f=json&pretty=true 看起来像 {"currentVersion" : 10.05, "folders" : [], "services" : [ {"name" : "appData/Drainage", "type" : "MapServer"}, {"name" : "appData/Parks",

如果我有一个rest服务URL,你能告诉我吗

http://domain.ca/ArcGIS/rest/services/appData?f=json&pretty=true
看起来像

{"currentVersion" : 10.05, 
  "folders" : [], 
  "services" : [
    {"name" : "appData/Drainage", "type" : "MapServer"}, 
    {"name" : "appData/Parks", "type" : "MapServer"}, 
    {"name" : "appData/Planning", "type" : "MapServer"}, 
    {"name" : "appData/QNet", "type" : "MapServer"}, 
    {"name" : "appData/Sanitary", "type" : "MapServer"}, 
    {"name" : "appData/Street_Lights", "type" : "MapServer"}, 
    {"name" : "appData/Survey", "type" : "MapServer"}, 
    {"name" : "appData/Transportation", "type" : "MapServer"}, 
    {"name" : "appData/Water", "type" : "MapServer"}
  ]
}
在python中,如何将
appData/
之后的所有名称加载到名为
servicesList
的列表中? 我试过类似的东西

myUrl = "http://domain.ca/ArcGIS/rest/services"
myRequest = myUrl
response = urllib2.urlopen(myRequest)
myJSON = response.read()
但不确定这是不是正确的方法

 serviceList= []
    for x in myJSON["services"]:
       name = x["name"]
       serviceList.append(name[name.index("/")+1:]) #Find the index of the / and add everything after it to the list
这将遍历服务中的所有名称,并根据需要将
/
后面的部分添加到服务列表中

编辑: 您还必须首先将读取的字符串转换为JSON。为此:

import json
newJSON = json.loads(myJSON)

您可以找到关于json的文档

当您以您所说的方式尝试时发生了什么?使用json模块使用
json.loads(myJSON)
解析此json。它将把它转换成一个python字典,您可以从中获得服务键,该键将返回一个字典列表。从列表中的每个字典中获取name属性,并将字符串“appData/”替换为“”,并将结果附加到服务列表获取
urlib2.HTTPError:HTTP错误404:Category not found
@cᴏʟᴅsᴘᴇᴇᴅ op可能意味着它是一个示例域。@technusm1我想向op展示如何处理请求,但我无法复制一个示例。谢谢,但我收到了这个错误
ValueError:在
newJSON=JSON.loads(myJSON)