有一個聊天內容我想分析。我得到了網址來獲取它的.json。所以它看起來像:如何從動態更新的json獲取最新數據?
{"messages":[
{"id":"111111","uid":"22222","name":"User","message":"Message","date":"2013-02-15 17:21:54","chatId":"111"},
{"id":"111111","uid":"22222","name":"User","message":"Message","date":"2013-02-15 17:21:54","chatId":"111"},
{"id":"111111","uid":"22222","name":"User","message":"Message","date":"2013-02-15 17:21:54","chatId":"111"}
]}
但是這json有一些限制,我想大約20-30記錄。新的記錄在開始處添加。它看起來像:
{"messages":[
{"id":"222222","uid":"33333","name":"User","message":"Message","date":"2013-02-15 18:21:59","chatId":"111"},
{"id":"111111","uid":"22222","name":"User","message":"Message","date":"2013-02-15 17:21:54","chatId":"111"},
{"id":"111111","uid":"22222","name":"User","message":"Message","date":"2013-02-15 17:21:55","chatId":"111"}
]}
.......
{"messages":[
{"id":"333333","uid":"44444","name":"User","message":"Message","date":"2013-02-15 19:13:34","chatId":"111"},
{"id":"222222","uid":"33333","name":"User","message":"Message","date":"2013-02-15 18:21:59","chatId":"111"},
{"id":"111111","uid":"22222","name":"User","message":"Message","date":"2013-02-15 17:21:54","chatId":"111"}
]}
我會讀通過GSON或JSON Java和地方的任何輸出此JSON,不要緊:)
但有關於如何解析任何新的最佳實踐記錄在動態更新的JSON?事實上,我不知道如何控制它被更新,但每秒鐘讀取它並將結果輸出,將導致數據重複,我認爲。
難道您不能控制這些數據嗎? – davidbuzatto 2013-02-15 13:53:04
@davidbuzatto,不,我不知道。我有一個chat.json文件的鏈接,該文件在數據庫中的數據更新後填充。所以我可以得到這個文件並反序列化。 – Dragon 2013-02-15 14:01:30
@AaronKurtzhals,目前我有解析.json文件的Java bean。我正在考慮顛倒數據數組並通過消息ID +消息日期進行比較。並以這種方式打印新消息。但我不知道這是否是一個好做法。 – Dragon 2013-02-15 14:04:24