android - SignPost error using OAuth and get Error parsing data org.json.JSONException: End of input at character 0 of -
i accessing magento backend android app using consumer. , getting following response magento after authentication done manually.
object(zend_http_response)#16 (5) { ["version":protected] => string(3) "1.1" ["code":protected] => int(200) ["message":protected] => string(2) "ok" ["headers":protected] => array(6) { ["date"] => string(29) "mon, 10 mar 2014 05:55:59 gmt" ["server"] => string(45) "apache/2.4.7 (win32) openssl/1.0.1e php/5.5.6" ["x-powered-by"] => string(9) "php/5.5.6" ["connection"] => string(5) "close" ["transfer-encoding"] => string(7) "chunked" ["content-type"] => string(31) "application/json; charset=utf-8" } ["body":protected] => string(27184) "6a23 {"16": {"entity_id":"16","attribute_set_id":"38","type_id":"simple","sku":"n2610","model":"2610","dimension":"4.1 x 1.7 x 0.7 inches ","description":"something"}}0"}
how parse above response in android app using signpost jar.in android using signpost java oauth library , there manually passing consumer key,consumer secret key,access token, , access token secret. java file below
package com.example.dukano; import java.io.bufferedreader; import java.io.console; import java.io.inputstream; import java.io.inputstreamreader; import java.io.unsupportedencodingexception; import oauth.signpost.oauthconsumer; import oauth.signpost.commonshttp.commonshttpoauthconsumer; import org.apache.http.httpentity; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.methods.httpget; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.util.entityutils; import org.json.jsonexception; import org.json.jsonobject; import android.content.context; import android.util.log; import android.widget.toast; public class jsonparser { static inputstream = null; static jsonobject jobj = null; static string json = ""; oauthconsumer consumer; public jsonparser(){ consumer = new commonshttpoauthconsumer("4fd325e8273924df5f48f978a3f8e556","46be40812031f40645788ee90894efbe"); consumer.settokenwithsecret("ca269640a3629a1d65af59d16058d91c", "f23ad8ba9646dbb28be5255c9faca0e1"); } //constructor public jsonobject getjsonfromurl(string url) { try { defaulthttpclient httpclient = new defaulthttpclient(); httpget request = new httpget(url); request.setheader("accept", "text/xml"); consumer.sign(request); org.apache.http.httpresponse response = httpclient.execute(request); // error caught here httpentity httpentity = response.getentity(); //string responsebody= entityutils.tostring(httpentity); //system.out .println(responsebody+"hello world"); = httpentity.getcontent(); } catch (unsupportedencodingexception e) { e.printstacktrace(); } catch (clientprotocolexception e) { e.printstacktrace(); } catch (exception 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(); log.i("json", json); } catch(exception e) {} try { jobj = new jsonobject(json); //showing parse error here } catch (jsonexception e) { log.e("my json parser", "error parsing data " + e.tostring()); } return jobj; } }
i found in debug mode
org.apache.http.httpresponse response = httpclient.execute(request);
above statement when execute goes try catch following :
try { jobj = new jsonobject(json); //showing parse error here } catch (jsonexception e) { log.e("my json parser", "error parsing data " + e.tostring()); }
Comments
Post a Comment