如本地有section.json文本,如:
{
"sections": [{
"subSections": [{
"template": 1,
"name": "观点",
"id": 6
},
{
"template": 1,
"name": "分享",
"id": 8
},
{
"template": 1,
"name": "学员",
"id": 17
},
{
"template": 1,
"name": "新闻",
"id": 19
}],
"template": 1,
"name": "视界",
"id": 1
},
{
"subSections": [{
"template": 4,
"name": "问答",
"id": 9
},
{
"template": 5,
"name": "投票",
"id": 10
},
{
"template": 6,
"name": "提问",
"id": 11
}],
"template": 4,
"name": "连线",
"id": 2
}]
}
从文件中得到json object,如:
public JSONObject getJSONObjFromLocal(Context context, String url) throws Exception {
InputStream is = context.getAssets().open("section.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
jsonStr = sb.toString();
jObj = new JSONObject(jsonStr);
return jObj;
}