java - json parsing function returns weird package name -


i have made json parsing class returns string. when set text of textview string, print 'com.test.app.jsonparser@41eddbf8'

what's going wrong?

heres parsing class

import android.os.asynctask; import android.util.log;  import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.client.methods.httpget; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.params.basichttpparams;  import java.io.bufferedreader; import java.io.inputstream; import java.io.inputstreamreader;  /**  * created vaibhav on 8/9/13.  */ public class jsonparser extends asynctask<string, void, string>{     protected string doinbackground(string... url) {         defaulthttpclient httpclient = new defaulthttpclient(new basichttpparams());         httpget httpget = new httpget(url[0]);         //httppost.setheader("content-type", "application/json");          inputstream inputstream = null;         string result;         try {         httpresponse response = httpclient.execute(httpget);         httpentity entity = response.getentity();          inputstream = entity.getcontent();         // json utf-8 default         bufferedreader reader = new bufferedreader(new inputstreamreader(inputstream, "utf-8"), 8);         stringbuilder sb = new stringbuilder();          string line;         while ((line = reader.readline()) != null)         {             sb.append(line + "\n");         }         result = sb.tostring();         return result;         } catch (exception e) {         log.d("com.test.app.jsonparser", "json error:" + e.tostring());         return null;     }     {         try{if(inputstream != null)inputstream.close();}catch(exception squish){}     } } } 

i call function like

string jsonstring = new jsonparser().execute(jsonurl).tostring(); 

i dont know why im getting weird response. thanks

edit:

so since wanted output in fragment, ended using

how result of onpostexecute() main activity because asynctask separate class?

to return json string calling fragment manipulate there.

edit 2:

omg!! easy. wasted time on this! else has problem, need add .get() @ end of call.

so: string jsonstring = new jsonparser().execute(jsonurl).get(); call , worked! didnt need onpostexecute block in asynctask.

the doinbackground method not return result when call execute, instead result passed onpostexecute method. looks using asynctask incorrectly. you'd result in onpostexecute needs main thread.

what seeing tostring output on jsonparser class, since asynctask return this when call execute.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -