Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON parsing in android app
    primarykey
    data
    text
    <p>The URL has the following view source.I need to parse and fetch the image path provided for "Folio".can anyone please guide how to get the array of the following paths.thanks in advance</p> <pre><code> {"SEO": {"Marketing":["http://www.tts.com/media/imagepath/Web.jpg","http://www.tts.com/imagepath/ranks.jpg"], "Folio":["http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_a_grade_motor_school.html_a_poftfolio_2013_01_11.png", "http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_abc_tarps.html_a_poftfolio_2013_01_10.png", "http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_able_scale.html_a_poftfolio_2013_01_10.png", "http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_accent_aluminum_windows.html_a_poftfolio_2013_01_10.png", "http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_access_health.html_a_poftfolio_2013_01_10.png", "http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_acmeda__zipscreen.html_a_poftfolio_2013_01_11.png", "http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_aditya_birla_minerals.html_a_poftfolio_2013_01_10.png", "http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_advanced_corporate_badges.html_a_poftfolio_2013_01_10.png", "http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_aerotech_fans.html_a_poftfolio_2013_01_10.png", "http://www.tts.com/media/imagepath/portfolio_images/http_arctictern.t.com.au_folio_portfolio_agriculture_victoria_services_.html_a_poftfolio_2013_01_10.png"]}, "Services":{"Hosting":["http://www.tts.com/media/imagepath/hostinga.jpg","http://www.tts.com/media/imagepath/hostingb.jpg"], "Mobile Apps":["http://www.tts.com/media/imagepath/mobileapp.jpg","http://www.tts.com/media/imagepath/mobilesite.jpg"] } } </code></pre> <p>The JSON parser class contains</p> <pre><code>public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } public JSONObject getJSONFromUrl(String url) { // Making HTTP request try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } // try parse the string to a JSON object try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } // return JSON String return jObj; } } </code></pre> <p>The main activity contains </p> <pre><code> public class AndroidJSONParsingActivity extends ListActivity { private static String url = "http://www.xyz.com/album_pro/array_to_encode"; private static final String TAG_FOLIO = "SEO"; JSONArray folio = null; @SuppressLint("NewApi") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); JSONParser jParser = new JSONParser(); try{ JSONObject json = jParser.getJSONFromUrl(url); Log.v("URL",json.toString()); JSONObject seo = json.getJSONObject("SEO"); Log.v("seo",seo.toString()); JSONArray folio = json.getJSONArray("Folio"); for(int i=0;i&lt; folio.length();i++) { Log.v("Test", "test"); } } catch(Exception e) { e.printStackTrace(); } } } </code></pre> <p>The error iam getting after runnning the app in logcat file is as follows</p> <pre><code>03-04 15:36:50.458: W/System.err(23230): org.json.JSONException: No value for Folio 03-04 15:36:50.458: W/System.err(23230): at org.json.JSONObject.get(JSONObject.java:354) 03-04 15:36:50.458: W/System.err(23230): at org.json.JSONObject.getJSONArray(JSONObject.java:544) 03-04 15:36:50.458: W/System.err(23230): at com.example.testgallery.AndroidJSONParsingActivity.onCreate(AndroidJSONParsingActivity.java:37) 03-04 15:36:50.458: W/System.err(23230): at android.app.Activity.performCreate(Activity.java:5008) 03-04 15:36:50.458: W/System.err(23230): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 03-04 15:36:50.458: W/System.err(23230): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload