如何写JSON文件来扩展数组?

时间:2013-06-08 09:05:34

标签: android json file io

我正在使用代码来保存json文件中的记录。 我希望得到结果:

 {
   "results":
           [{record1},{record2}]
 }

但我得到了:

 {
  "results":
          [{record1}]}{"results":[{record2}]
 }

我需要改变什么来获得所需的模式?

方法调用:

writeJSONtoFile(saveJSON.toString());


private void writeJSONtoFile(String jsnStr) {
    FileOutputStream fos;
    try {

        fos = openFileOutput("json_local.xml", Context.MODE_APPEND);
        fos.write(jsnStr.getBytes());
        Log.i("json_convert", jsnStr);
        fos.flush();
        fos.close();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    Log.i("Favorites", "" + jsnStr);
    Toast.makeText(getApplicationContext(),
            item_title + " добавлено в избранное", Toast.LENGTH_SHORT)
            .show();
}

实际saveJSON

{"count_page":1,
 "count":"1",
 "results":[ 
            { "id":"7471673",            
              "operation":"prodazha",
              "realty_type":"zhilaya",
              "object":"kvartira",
              "country_title":null,
              "region_title":"\u041a\u0438\u0435\u0432\u0441\u043a\u0430\u044f \u043e\u0431\u043b.",  
              "district_title":"\u0433.\u041a\u0438\u0435\u0432","settle_title":null, "street":"\u043f\u0435\u0440.\u041b\u043e\u0431\u0430\u0447\u0435\u0432\u0441\u043a\u043e\u0433\u043e, 7",
              "title":"\u041f\u0440\u043e\u0434\u0430\u0436\u0430 2 \u043a\u043e\u043c\u043d\u0430\u0442\u043d\u043e\u0439 \u043a\u0432\u0430\u0440\u0442\u0438\u0440\u044b",
              "rooms":"2",
              "floor":"13",
              "floors":"25",
              "sqTotal":"63",
              "sqLiving":"35",
              "sqKitchen":"9",
              "sqLand":"0",
              "unitLand":"0",
              "distance":"0",
              "upddate":"2013-06-06 17:54:55",                  "description":"\u0416\u041a\u00ab\u0424\u041b\u0410\u0413\u041c\u0410\u041d\u00bb \u0414\u043d\u0435\u043f\u0440\u043e\u0432\u0441\u043a\u0438\u0439 \u0440\u0430\u0439\u043e\u043d, \u043f\u0435\u0440. \u041b\u043e\u0431\u0430\u0447\u0435\u0432\u0441\u043a\u043e\u0433\u043e, 7 (\u0440-\u043d \u041b\u0435\u043d\u0438\u043d\u0433\u0440\u0430\u0434\u0441\u043a\u043e\u0439 \u043f\u043b\u043e\u0449\u0430\u0434\u0438)\n\u0414\u043e\u043c \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043d\u043e-\u043a\u0430\u0440\u043a\u0430\u0441\u043d\u044b\u0439. \u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0449\u0430\u0434\u044c 63.4\u043c.\u043a\u0432., \u043a\u043e\u043c\u043d\u0430\u0442\u0430 35.27\u043c.\u043a\u0432., \u043a\u0443\u0445\u043d\u044f 8.52\u043c.\u043a\u0432. \u0411\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0435 \u0441\u0442\u0430\u043d\u0446\u0438\u0438 \u043c\u0435\u0442\u0440\u043e \u2013 \u00ab\u043c. \u0414\u0430\u0440\u043d\u0438\u0446\u0430\u00bb, \u00ab\u043c. \u0427\u0435\u0440\u043d\u0438\u0433\u043e\u0432\u0441\u043a\u0430\u044f\u00bb,\n\u00ab\u043c. \u0425\u0430\u0440\u044c\u043a\u043e\u0432\u0441\u043a\u0430\u044f\u00bb. \u0420\u044f\u0434\u043e\u043c \u0434\u0432\u0430 \u0434\u0435\u0442\u0441\u043a\u0438\u0445 \u0441\u0430\u0434\u0430, \u0438 \u0434\u0432\u0435 \u0448\u043a\u043e\u043b\u044b.\n\u0421\u0440\u043e\u043a \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 II \u043a\u0432\u0430\u0440\u0442\u0430\u043b 2013 \u0433\u043e\u0434\u0430. \u041f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0433\u043e\u0432\u043e\u0440 \u0441 \u0437\u0430\u0441\u0442\u0440\u043e\u0439\u0449\u0438\u043a\u043e\u043c. \u0420\u0430\u0441\u0441\u0440\u043e\u0447\u043a\u0430 \u0434\u043e 5\u043b\u0435\u0442.",
              "not_photo":"http:\/\/img.mirkvartir.ua\/81\/fd\/9e-list.jpg",
              "premium":"1",
              "up":"1","price":"472,500",
              "pricefor_title":"\u0437\u0430 \u0432\u0441\u0435",
              "currency_title":"\u0433\u0440\u043d",
              "email":"flaghman@mail.ua",
              "phone1":"(067)525-88-18",
              "phone2":"","user_contact":" ",
              "user_firm":"",
              "coords":"",
              "href":"http:\/\/mirkvartir.ua\/offers\/view\/7471673-prodazha-2-komnatnoj-kvartiry.html"}
              ]
            }

0 个答案:

没有答案