使用VB.NET 这是我的HTTP请求:
https://inventory.data.gov/api/action/datastore_search?resource_id=8ea44bc4-22ba-4386-b84c-1494ab28964b&filters= {%22FiscalYear%22:%222017 22%,%22Zip%22:%2290210%22}
(抱歉,我无法获得格式正确的链接)
我收到回复并解析它。我无法仅提取“餐”。从退回的比率。
Dim json As String = responseFromServer
Dim ser As JObject = JObject.Parse(json)
Dim data As List(Of JToken) = ser.Children().ToList
Dim output As String = ""
For Each item As JProperty In data
--> Not sure what to do in here.
Next
非常感谢您的协助。
答案 0 :(得分:1)
从API返回的JSON看起来像这样(删除了一些数据以节省空间):
{ "help": "https://inventory.data.gov/api/3/action/help_show?name=datastore_search", "success": true, "result": { "resource_id": "8ea44bc4-22ba-4386-b84c-1494ab28964b", "fields": [ ...snip... ], "records": [ { "City": "Los Angeles", "Dec": "158", "Feb": "175", "Zip": "90210", "Aug": "158", "Sep": "158", "Apr": "158", "Jun": "158", "State": "CA", "Jul": "158", "Meals": "64", "County": "Los Angeles County, CA", "May": "158", "DestinationID": "22", "Mar": "175", "Jan": "175", "LocationDefined": "Los Angeles / Orange / Ventura / Edwards AFB less the city of Santa Monica", "Nov": "158", "_id": 39056, "Oct": "158", "FiscalYear": "2017" } ], "_links": { "start": "/api/action/datastore_search?filters=%7B%22FiscalYear%22%3A%222017%22%2C%22Zip%22%3A%2290210%22%7D&resource_id=8ea44bc4-22ba-4386-b84c-1494ab28964b", "next": "/api/action/datastore_search?offset=100&filters=%7B%22FiscalYear%22%3A%222017%22%2C%22Zip%22%3A%2290210%22%7D&resource_id=8ea44bc4-22ba-4386-b84c-1494ab28964b" }, "filters": { "Zip": "90210", "FiscalYear": "2017" }, "total": 1 } }
将数据解析为JObject
后,您只需向下钻取结构即可获得所需的值:
Dim ser As JObject = JObject.Parse(json)
Dim mealRate = CInt(ser("result")("records")(0)("Meals"))