java - Send multiple records via json to php mysql -
how send more 1 record @ time using json? code sample found online need send 100 objects or records @ time. data comes database.
protected string doinbackground(string... args) { string name = inputname.gettext().tostring(); string price = inputprice.gettext().tostring(); string description = inputdesc.gettext().tostring(); // building parameters list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("name", name)); params.add(new basicnamevaluepair("price", price)); params.add(new basicnamevaluepair("description", description)); // getting json object // note create product url accepts post method jsonobject json = jsonparser.makehttprequest(url_create_product, "post", params);
you must create jsonobject represent objects, , add request:
if have structure example:
{[{name:"name1",price:"10"},{name:"name2",price:"15"}]}
jsonarray elements=new jsonarray(); jsonobject aux=new jsonobject().put("name", "name1"); aux.put("price", 10); array.put(aux); aux=new jsonobject().put("name1", "name2"); aux.put("price", 20); array.put(aux); list<namevaluepair> parameters= new arraylist<namevaluepair>(); parameters.add(new basicnamevaluepair("json", elements.tostring())); httppost post = new httppost(url); post.setentity(new urlencodedformentity(pairs)); httpclient cliente = createhttpclient(); return cliente.execute(post);
and in server catch parameter "json"
Comments
Post a Comment