2012-10-01 53 views
0

Iam在一個android應用程序中工作,其中我從JSON格式的服務器獲得響應。我想將鍵值對存儲在strings.xml中。它怎麼做? JSON響應如下。在Android中的strings.xml中編寫

{ 
"ResourceStrings": [ 
    { 
     "Key": "AccountNumber", 
     "Value": "Account Number" 
    }, 
    { 
     "Key": "AccountPassword", 
     "Value": "Account Password" 
    }, 
    { 
     "Key": "AccountSettings", 
     "Value": "Account" 
    }, 
    { 
     "Key": "AccountSettings.Load.InfoMessage", 
     "Value": "The Account Number and Password only needs to be set one time. \r\n\r\nIf you do not know the Account information please contact you system administrator or your DataXchange reseller." 
    }, 
    { 
     "Key": "Add", 
     "Value": "Setup" 
    }, 
    { 
     "Key": "AddandModifytheScreens", 
     "Value": "Add and Modify the Screens" 
    }, 
    { 
     "Key": "AddButton", 
     "Value": "Add" 
    }, 
    { 
     "Key": "AddButtonClick.InfoMessage", 
     "Value": "Enter the new information and press the Enter button to save the changes.\r\n\r\nOr, press the Cancel button to discard the new information." 
    }, 
    { 
     "Key": "AddCommunication", 
     "Value": "Add Communication" 
    }, 
    { 
     "Key": "AdvancedSettings", 
     "Value": "Advanced Settings" 
    } 
] 
} 
+0

strings.xml並不意味着存儲在運行時生成的數據。它用於存儲用於佈局的任何常量等。考慮使用SharedPreferences,平面文件或數據庫來存儲這些字符串。 –

+0

User Array ArrayList/Array存儲這些值並使用它,在需要的地方。 – Aerrow

+0

@VinaySShenoy感謝您的建議,現在請您告訴我如何使用共享偏好保存此響應? –

回答

7

你不能在運行時在strings.xml中寫任何東西。相反,您可以寫入共享首選項,數據庫或內部/外部存儲器中的文件。所有這些方式都在Android Developers site上列出。

相關問題