java - http POST Formatting Issue - As array, list? -


i attempting make "freebusy" request connect google calendar api. stuck on formatting http post. getting error:

{   "error": {    "errors": [     {      "domain": "global",      "reason": "parseerror",      "message": "parse error"     }    ],    "code": 400,    "message": "parse error"   } } 

i attempting format request this:

{   "timemin": datetime,   "timemax": datetime,   "timezone": string,   "groupexpansionmax": integer,   "calendarexpansionmax": integer,   "items": [     {       "id": string     }   ] } 

and doing format it:

string[] stringpairs = new string[]{             "timemin",       date1,             "timemax",       date2,             "items[]",       calendarid,             "timezone",      "canada/toronto"};  //create http post request httpclient client = new defaulthttpclient(); httppost post = new httppost("hostulr"); list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(stringpairs.length/2 - 1);  (int = 0; < stringpairs.length; += 2) {     namevaluepairs.add(new basicnamevaluepair(stringpairs[i], stringpairs[i+1])); }  post.setentity(new urlencodedformentity(namevaluepairs)); org.apache.http.httpresponse response = client.execute(post); httpentity entity = response.getentity(); 

i believe part screwing on "items" part. appreciated.

don't know if correct java in c plug json make complex json.

maybe website can you.

https://code.google.com/p/json-simple/wiki/encodingexamples#example_1-3_-_encode_a_json_object_-_using_map

edit: noticed form array of objects... correct implementation this.

  jsonobject obj=new jsonobject();   obj.put("id", string);    jsonarray list = new jsonarray();    list.add(obj);    jsonobject jsonobj = new jsonobject();{             object.put("timemin", date1)             .... 

also, don't know code...

"timezone",      "canada/toronto"}, accesstoken ); 

with json objects it's {} symbolizes json objects [] these arrays.

edit 2: after creating json this

stringentity entity = new stringentity(json.tostring());                      entity.setcontenttype("application/json;charset=utf-8");                      entity.setcontentencoding(new basicheader(http.content_type,"application/json;charset=utf-8"));                      request.setheader("accept", "application/json");                      request.setentity(entity);                        httpresponse response =null;                      defaulthttpclient httpclient = new defaulthttpclient();                       httpconnectionparams.setsotimeout(httpclient.getparams(), constants.android_connection_timeout*1000);                       httpconnectionparams.setconnectiontimeout(httpclient.getparams(),constants.android_connection_timeout*1000);                       try{                       response = httpclient.execute(request);                       }                      catch(socketexception se)                      {                          log.e("socketexception", se+"");                          throw se;                      }     inputstream in = response.getentity().getcontent(); bufferedreader reader = new bufferedreader(new inputstreamreader(in)); string line = null; while((line = reader.readline()) != null){     sb.append(line); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -