1

このアプリでは、次のような情報を含む JSON ファイルを作成します。

{
   "sites":{
      "site":[
         {
            "src":"/Users/redoddity/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/EE5BB071-A217-4C8D-99BA-5B6F392889A6/Documents/Sito3.html",
            "name":"Sito3",
            "expiryDate":"29 Ago 2013"
         },
         {
            "src":"/Users/redoddity/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/EE5BB071-A217-4C8D-99BA-5B6F392889A6/Documents/Sito2.html",
            "name":"Sito2",
            "expiryDate":"29 Ago 2013"
         }
      ]
   }
}

(これは、iPhone アプリ用に作成した JSON です)。次に、Android アプリ用の JSON ファイルを作成する必要があります。

最初の質問: Android で JSON を作成するにはどうすればよいですか?

2 番目の質問: 私の JSON には、iPhone の Documents フォルダーにダウンロードした html ファイルのパスがあることがわかります。Android では、次のコードで html を保存しました。

File file = getFileStreamPath(titleText + ".html");
    if (!file.exists()) {
          try {
        OutputStreamWriter out = new OutputStreamWriter(openFileOutput(titleText + ".html", 0));
        out.write(html);
        out.close();
        } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
        }
    } else {
          Log.d("FILE", "Il file esiste");
          alert.show();
}

このファイルが保存されているパスを知るにはどうすればよいですか?

ありがとうございました

4

2 に答える 2

3

getFileStreamPath を使用する

File file = getFileStreamPath(titleText + ".html");

ドキュメントから

openFileOutput(String, int) で作成されたファイルが保存されているファイルシステム上の絶対パスを返します。

JSONObject root = new JSONObject();
JSONArray arr = new JSONArray();
root.put("key",(Object)arr);
于 2013-08-02T10:28:58.827 に答える