簡體   English   中英

使用Unity Boomlagoon Json遍歷所有json元素

[英]Looping through all json elements using Unity Boomlagoon Json

我在Unity項目中使用的是Boomlagoon Json。 我的Json文件中有幾行,到目前為止,我只能讓Boomlagoon僅讀取第一個文件。 有沒有一種方法可以使我遍歷整個json文件的循環?

這是我的json:

{"type": 1, "squads": [{"player_id": 1, "squad": [1, 2, 3, 4]}, {"player_id": 2, "squad": [6, 7, 8, 9]}], "room_number": 1, "alliance_id": 1, "level": 1}
{"type": 2, "squads": [{"player_id": 2, "squad": [1, 2, 3, 4]}, {"player_id": 3, "squad": [6, 7, 8, 9]}], "room_number": 2, "alliance_id": 1, "level": 1}
{"type": 3, "squads": [{"player_id": 3, "squad": [1, 2, 3, 4]}, {"player_id": 4, "squad": [6, 7, 8, 9]}], "room_number": 3, "alliance_id": 1, "level": 1}

當我做這樣的循環:

foreach (KeyValuePair<string, JSONValue> pair in emptyObject) { ... }

它只會為我提供第一個條目的結果(在本示例中為:1)。 謝謝。

您的文件實際上包含3個JSON對象,並且在解析時會發生的情況是,一旦第一個對象結束,解析就會停止。 您需要分別解析每行以獲取所有數據。

順便一句 ,您會注意到,如果將JSON粘貼到jsonlint.com的驗證器中, 則會在第二個對象開始的地方出現解析錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM