我有以下json文件.我想知道在哪里将json文件放在我的项目中以及如何阅读和存储它.
{
"aakash": [
    [  0.070020,0.400684],
    [  0.134198,0.515837],
    [  0.393489,0.731809],
    [  0.281616,0.739490]
],
"anuj": [
    [  1287.836667,-22.104523],
    [  -22.104523,308.689613],
    [  775.712801,-13.047385],
    [  -13.047385,200.067743]
]
}
Fai*_*zan 202
将该文件放入资产中.
对于在Android Studio项目中创建的项目,您需要在主文件夹下创建assets文件夹.
将该文件读取为:
public String loadJSONFromAsset(Context context) {
        String json = null;
        try {
            InputStream is = context.getAssets().open("file_name.json");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
        return json;
    }
然后您可以string通过此函数简单地读取此返回值
JSONObject obj = new JSONObject(json_return_by_the_function);
有关JSON的更多详细信息,请参阅 http://www.vogella.com/articles/AndroidJSON/article.html
希望你能得到你想要的东西.
| 归档时间: | 
 | 
| 查看次数: | 120282 次 | 
| 最近记录: |