java - What will be the structure of JSON string inside POST array -


here java program trying send json object server. i'm using apache httpclient http requests , jettison json library.

i have few question this.

  1. what structure of json string inside post array. {xxxxx:{userid:userid, blha, blha, blha.........}}

  2. if need json string (no need convert object) post array in server side. how that? in php echo $_post["xxxxxxx"];

  3. usually there name each data in post array. below program doesnt specify name json object. name(xxxxxxx) below json string inside post array.


string base_url = "https://abc.com/"; string username = "test_user"; string password = "test_user_pw"; string client_id = "test_user123"; string client_secret = "test_user1234567"; string login_url = base_url + "session/login";  closeablehttpclient wf_client = httpclients.custom().setuseragent(client_id + "/1.0").build(); httppost login_post = new httppost(loginurl); jsonobject login_object = new jsonobject(); try {     login_object.put("userid", username);     login_object.put("password", password);     login_object.put("clientid", client_id);     login_object.put("clientsecret", client_secret); } catch (jsonexception ex) {     system.out.println(ex.tostring()); }  stringentity post_entity = new stringentity(login_object.tostring(), jason_content_type); login_post.setentity(post_entity); closeablehttpresponse responce = wf_client.execute(login_post); 

answering questions following same structure

  • you right, that's structure of json string. exact syntax can found in json.org website.

example:

{     "userid" : "username",    "array"  : [ "1", "2", "3" ],    "object" : {       "objectid" : "bkadakdbk",       ...    } } 
  • in java have read data comes in http request in server side (usually servlet):

example:

bufferedreader rd = new bufferedreader(new inputstreamreader(request.getinputstream())); stringbuffer result = new stringbuffer(); string line = ""; while ((line = rd.readline()) != null) {     result.append(line); } 
  • in java when make post request sending json object contents of request, there no parameter array in server side, that's why have read contents of request in previous example.

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -