json - Unable to get the value of JSONObject in android -


i unable value of "wpcf-video" , "wpcf-icon" "custom_fields" object json url. want value if each "wpcf" inside custom fields , string can "putextra" value of , getintent in next activity. please help. im beginner in android , helpful if straight forward solution, im doing thesis in university. thank understanding..

json url:

    "status": "ok",     "count": 3,     "count_total": 3,     "pages": 1,     "posts": [    {   "id": 85,   "title": "lesson 3 commarts",   "content": "<p>lesson 3 commarts content here<\/p>\n",   "excerpt": "<p>lesson 3 commarts content here<\/p>\n",   "custom_fields": {     "wpcf-video": [       ""     ],     "wpcf-pdf": [       ""     ],     "wpcf-icon": [       "http:\/\/loaapp.abundantlife.org.au\/wp-content\/uploads\/2014\/04\/icon2.png"     ]   } }, {   "id": 81,   "title": "lesson 2 com arts 1",   "content": "<p>lesson 2 com arts 1 content here<\/p>\n",   "excerpt": "<p>lesson 2 com arts 1 content here<\/p>\n",   "custom_fields": {     "wpcf-video": [       ""     ],     "wpcf-pdf": [       "http:\/\/loaapp.abundantlife.org.au\/wp-content\/uploads\/2014\/04\/single-course-layout.docx"     ],     "wpcf-icon": [       "http:\/\/loaapp.abundantlife.org.au\/wp-content\/uploads\/2014\/04\/iconmenu.png"     ]   } } 

my code:

    try {                  httpclient client = new defaulthttpclient();                 httppost post = new httppost(params[0]);                 httpresponse response = client.execute(post);                  int status = response.getstatusline().getstatuscode();                  if(status == 200){                      httpentity entity = response.getentity();                     string data = entityutils.tostring(entity);                      jsonobject lessonobject = new jsonobject(data);                     jsonarray lessonarray = lessonobject.getjsonarray("posts");                      (int = 0; < lessonarray.length(); i++){                          jsonobject objectlesson = lessonarray.getjsonobject(i);                          lessonarraytemplate lessontemplatearraylist = new lessonarraytemplate();                          lessontemplatearraylist.settitle(objectlesson.getstring("title"));                         lessontemplatearraylist.setexcerpt(objectlesson.getstring("excerpt").replaceall("<(.*?)\\>","").replacefirst("(.*?)\\>", "").replaceall("&rarr;","").replace("continue reading", ""));                         lessontemplatearraylist.setid(objectlesson.getstring("id"));                          jsonobject customfieldsobject = objectlesson.getjsonobject("custom_fields");                          //fetching url of video                         lessontemplatearraylist.setvideo(customfieldsobject.getstring("wpcf-video").replace("\\", ""));                         lessontemplatearraylist.seticonimage(customfieldsobject.getstring("wpcf-icon").replace("\\", ""));                           // sample input should image                           comartsarraylist.add(lessontemplatearraylist);                       } 

do way

replace these 2 lines

lessontemplatearraylist.setvideo(customfieldsobject.getstring("wpcf-video").replace("\\", "")); lessontemplatearraylist.seticonimage(customfieldsobject.getstring("wpcf-icon").replace("\\", "")); 

with

lessontemplatearraylist.setvideo(customfieldsobject.getjsonarray("wpcf-video").getstring(0));     lessontemplatearraylist.seticonimage(customfieldsobject.getjsonarray("wpcf-icon").getstring(0)); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -