0
json 배열 및 개체를 포함하는 내 sd 카드에 다음 텍스트 파일이 있습니다. sucessfully 첫 번째 json 배열 "데이터"구문 분석 오전, 지금은 어떻게 생각이 나 두 번째 및 세 번째 json 배열을 "비디오"및 "이미지"로 파싱 할 수 있습니까? 모든 데이터 (예 : 비디오 및 이미지)는 SD 카드에 저장됩니다. 도움이 될만한 점은 많이 있습니다. 감사합니다.안드로이드 어떻게 여러 json 배열 및 개체를 sd 카드에서 구문을
my textfile "textarabics.txt"
{
"data": [
{
"id": "1",
"title": "تخطي نوجا نوجا أخبار واستعراض السوق",
"duration": 10
},
{
"id": "2",
"title": "أحدث نوجا الأخبار وآخر المستجدات",
"duration": 3
},
{
"id": "3",
"title": "نوجا الأخبار وآخر المستجدات",
"duration": 5
},
{
"id": "4",
"title": "لا تحتوي على تطبيقات وجد نوع الكلمة",
"duration": 7
},
{
"id": "5",
"title": "تحتاج إلى إعادة تشغيل التطبيق لاتخاذ تغييرات الخط. هل تريد إعادة التشغيل الآن",
"duration": 4
}
],
"videos": [
{
"id": "1",
"video": "VEVUE_video-2013-11-21-16-50-20.mp4"
},
{
"id": "2",
"video": "VEVUE_video-2013-12-30-17-47-44.mp4"
},
{
"id": "3",
"video": "video-2013-09-18-12-41-59.mp4"
}
],
"images": [
{
"bgimage": "nogastorebgimage.png",
"logoimage": "welcometonoga.png"
}
]
}
내가 성공적으로 1 JSON 배열 "데이터"와 개체를 구문 분석 한
내 코드 :
jsona 배열과 객체를 포함 617,451,515,try {
File yourFile = new File(Environment.getExternalStorageDirectory(), "textarabics.txt");
FileInputStream stream = new FileInputStream(yourFile);
String jsonStr = null;
try {
FileChannel fc = stream.getChannel();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
jsonStr = Charset.forName("UTF-8").decode(bb).toString();
Log.d("Noga Store", "jString = " + jsonStr);
}
finally {
stream.close();
}
Log.d("Noga Store", "jString = " + jsonStr);
// A JSONTokener is needed in order to use JSONObject correctly
JSONTokener jsonTokener = new JSONTokener(jsonStr);
// Pass a JSONTokener to the JSONObject constructor
JSONObject jsonObj = new JSONObject(jsonTokener);
// Getting data JSON Array nodes
JSONArray data = jsonObj.getJSONArray("data");
// looping through All nodes
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
String id = c.getString("id");
String title = c.getString("title");
// String duration = c.getString("duration");
int duration = c.getInt("duration");
// tmp hashmap for single node
/* HashMap<String, String> parsedData = new HashMap<String, String>();
// adding each child node to HashMap key => value
parsedData.put("id", id);
parsedData.put("title", title);
parsedData.put("duration", duration);*/
textnames.add(title);
textduration.add(duration);
// textnames.add(duration);
// do what do you want on your interface
}
} catch (Exception e) {
e.printStackTrace();
}
확인을 내 동영상 파일이 SD 카드와 폴더 이름 "nogastore"에 배치 "데이터"JSON 배열에 대해 그랬던 것처럼 당신은 동일 할 수있다 .. 비디오에서 동일한 과정을 수행하면 비디오를 얻을 수 있습니까? –
당신은 그것을 위해 여분의 노력을해야합니다. json 응답은 비디오의 전체 경로가 아닌 파일 이름 만 반환하므로 해당 파일에 액세스하기 전에 파일 경로를 추가해야합니다. – Sonali8890
"/ sdcard/nogastore /"+ your_filename과 같은 작업을 수행해야합니다 – Sonali8890