0
我在做一個使用Java的小遊戲,這是我的一個項目。作爲一個實驗,我試圖添加語言支持,以便玩我遊戲的兩個人可以自由切換遊戲文本的語言。JSON翻譯系統
使用JSON,我創建了一個文件,其中包含一些文本,我計劃翻譯成其他語言。它存儲在EN_US.json:
{
"name": "English",
"country": "US",
"code": "EN_US",
"index": 0,
"translations": {
"mainMenu": {
"gameName": "Ludicrous Swole",
"startConfirm": "PRESS ANY KEY TO BEGIN",
"singlePlayer": "Singleplayer",
"multiPlayer": "Multiplayer",
"quit": "Quit",
"options": {
"desc": "Options"
},
"easy": "Easy",
"normal": "Normal",
"hard": "Hard"
}
}
}
使用JSON解釋庫傑克遜(或任何其他爲此事),我怎麼能轉換成東西,我可以很容易地在字符串中引用此?
System.out.println("The difficulty is set to " + /* translations.mainMenu.easy */);
如果答案可以提供相關的進口,這也是有幫助的,因爲我不擅長這一點。
您可以嘗試使用GSON庫。 http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/index.html – Lokesh 2015-02-06 02:43:47