Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Power Lifting Lever Belt
SkullVamp
Updated:
Saturday at 10:32 PM
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Saturday at 3:55 PM
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Thursday at 2:23 PM
Ad icon
Wechat qr verification
Pawan2005
Updated:
Thursday at 1:28 AM
🚀 GOOGLE AI PRO 18 MONTHS ACTIVATION 🚀
sayuru bandara
Updated:
Jun 10, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
Json parsing help!!
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="san**" data-source="post: 16891417" data-attributes="member: 392854"><p>//JSONParser.java</p><p></p><p>package com.ill.supportlibs;</p><p></p><p>import java.io.BufferedReader;</p><p>import java.io.IOException;</p><p>import java.io.InputStream;</p><p>import java.io.InputStreamReader;</p><p>import java.io.UnsupportedEncodingException;</p><p>import java.util.List;</p><p> </p><p>import org.apache.http.HttpEntity;</p><p>import org.apache.http.HttpResponse;</p><p>import org.apache.http.NameValuePair;</p><p>import org.apache.http.client.ClientProtocolException;</p><p>import org.apache.http.client.entity.UrlEncodedFormEntity;</p><p>import org.apache.http.client.methods.HttpGet;</p><p>import org.apache.http.client.methods.HttpPost;</p><p>import org.apache.http.client.utils.URLEncodedUtils;</p><p>import org.apache.http.impl.client.DefaultHttpClient;</p><p>import org.json.JSONException;</p><p>import org.json.JSONObject;</p><p> </p><p>import android.util.Log;</p><p> </p><p>public class JSONParser {</p><p> </p><p> static InputStream is = null;</p><p> static JSONObject jObj = null;</p><p> static String json = "";</p><p> </p><p> // constructor</p><p> public JSONParser() {</p><p> </p><p> }</p><p> </p><p> // function get json from url</p><p> // by making HTTP POST or GET mehtod</p><p> public JSONObject makeHttpRequest(String url, String method,</p><p> List<NameValuePair> params) {</p><p> </p><p> // Making HTTP request</p><p> try {</p><p> </p><p> // check for request method</p><p> if(method == "POST"){</p><p> // request method is POST</p><p> // defaultHttpClient</p><p> DefaultHttpClient httpClient = new DefaultHttpClient();</p><p> HttpPost httpPost = new HttpPost(url);</p><p> httpPost.setEntity(new UrlEncodedFormEntity(params));</p><p> </p><p> HttpResponse httpResponse = httpClient.execute(httpPost);</p><p> HttpEntity httpEntity = httpResponse.getEntity();</p><p> is = httpEntity.getContent();</p><p> </p><p> }else if(method == "GET"){</p><p> // request method is GET</p><p> DefaultHttpClient httpClient = new DefaultHttpClient();</p><p> String paramString = URLEncodedUtils.format(params, "utf-8");</p><p> url += "?" + paramString;</p><p> HttpGet httpGet = new HttpGet(url);</p><p> </p><p> HttpResponse httpResponse = httpClient.execute(httpGet);</p><p> HttpEntity httpEntity = httpResponse.getEntity();</p><p> is = httpEntity.getContent();</p><p> } </p><p> </p><p> } catch (UnsupportedEncodingException e) {</p><p> e.printStackTrace();</p><p> } catch (ClientProtocolException e) {</p><p> e.printStackTrace();</p><p> } catch (IOException e) {</p><p> e.printStackTrace();</p><p> }</p><p> </p><p> try {</p><p> BufferedReader reader = new BufferedReader(new InputStreamReader(</p><p> is, "iso-8859-1"), 8);</p><p> StringBuilder sb = new StringBuilder();</p><p> String line = null;</p><p> while ((line = reader.readLine()) != null) {</p><p> sb.append(line + "\n");</p><p> }</p><p> is.close();</p><p> json = sb.toString();</p><p> } catch (Exception e) {</p><p> Log.e("Buffer Error", "Error converting result " + e.toString());</p><p> }</p><p> </p><p> // try parse the string to a JSON object</p><p> try {</p><p> jObj = new JSONObject(json);</p><p> } catch (JSONException e) {</p><p> Log.e("JSON Parser", "Error parsing data " + e.toString());</p><p> }</p><p> </p><p> // return JSON String</p><p> return jObj;</p><p> </p><p> }</p><p>}</p></blockquote><p></p>
[QUOTE="san**, post: 16891417, member: 392854"] //JSONParser.java package com.ill.supportlibs; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONException; import org.json.JSONObject; import android.util.Log; public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } // function get json from url // by making HTTP POST or GET mehtod public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) { // Making HTTP request try { // check for request method if(method == "POST"){ // request method is POST // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(params)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); }else if(method == "GET"){ // request method is GET DefaultHttpClient httpClient = new DefaultHttpClient(); String paramString = URLEncodedUtils.format(params, "utf-8"); url += "?" + paramString; HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); 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; } } [/QUOTE]
Insert quotes…
Verification
Awruddata maasa keeyada?
Post reply
Top
Bottom