0
我正在編寫一個移動客戶端,它使用來自第三方服務器(我無法控制的)的JSON數據。問題是,當我做以下網址挖掘到JSON對象的REST URL
curl http://server.com/zm/api/events.json
它返回的結構,像這樣的事件的大名單的獲取:
"events": [
{
"Event": {
"Id": "280",
"MonitorId": "1",
"Name": "Familyroom-280",
"Cause": "Motion",
"StartTime": "2015-04-12 06:54:43",
"EndTime": "2015-04-12 06:55:27",
"Width": "1280",
"Height": "960",
"Length": "44.24",
"Frames": "74",
"AlarmFrames": "23",
"TotScore": "973",
"AvgScore": "42",
"MaxScore": "279",
"Archived": "0",
"Videoed": "0",
"Uploaded": "0",
"Emailed": "0",
"Messaged": "0",
"Executed": "0",
"Notes": "Motion: mudroom door, study door"
}
}, //and many more such "Event" events inside the array
我是新來的JSON,但是當我讀了,其規範說服務器必須提供一種機制來提取任何子對象。因此,舉例來說,我要建立一個網址,以僅獲取其中有1
一個MonitorId我已經試過
curl http://server.com/zm/api/events/Event/MonitorId/1.json
curl http://server.com/zm/api/Event/MonitorId/1.json
curl http://server.com/zm/api/events.json?MonitorId="1"
curl http://server.com/zm/api/events.json?Event.MonitorId="1"
但我似乎無法得到它的權利的事件。有人可以建議什麼是我需要構造的URL只返回MonitorId =「1」的元素?
謝謝!
你從哪裏讀到服務器必須提供一種機制來提取任何子對象? – mason
每個網站都有自己的API。你必須閱讀'server.com'中的文檔,以便知道什麼是正確的URL。 – nZeus
哎呀。對不起 - 我正在閱讀http://jsonapi.org/format/,並且我誤讀了「服務器必須支持爲每個提供的URL提取資源數據」,因爲「服務器必須支持爲每個提供的對象提取資源數據」 Shucks。我認爲這就像xpath,我可以鑽到我想要的任何級別。服務器使用CakePHP實現它的api – user1361529