devo inviare i seguenti dati per webservice all'indirizzo URLCome inviare dati a un servizio Web utilizzando JSON?
Il formato dei dati da trasmettere è:
new_member=[{"email":"[email protected]","username":"himanshu01","pwd":"himanshu01"}]
dove email
, username
e pwd
è la chiave e ha stringa corrispondente valore recuperati attraverso EditText stringa. Sto postando questi dati cliccando sul pulsante.
Non riesco a ottenere alcuna risposta bcoz ho provato a contrastare questo con il mio co-sviluppatore nella sua versione iphone iphone app stessa come il nome utente e la password non è valida è detto dal server.
La mia classe è Signup.java
:
Button b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener()
{
EditText e=(EditText)findViewById(R.id.editText1);
String a=e.getText().toString();
EditText e1=(EditText)findViewById(R.id.editText1);
String b=e1.getText().toString();
EditText e2=(EditText)findViewById(R.id.editText1);
String c=e2.getText().toString();
public void onClick(View v) {
// TODO Auto-generated method stub
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;
JSONObject json = new JSONObject();
try{
HttpPost post = new HttpPost("URL");
//System.out.println(post);
json.put("email", a);
json.put("username", b);
json.put("pwd",c);
StringEntity se = new StringEntity("JSON: " + json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setEntity(se);
response = client.execute(post);
/*Checking response */
if(response!=null){
InputStream in = response.getEntity().getContent(); //Get the data in the entity
//System.out.println(response);
}
}
catch(Exception e){
e.printStackTrace();
System.out.println(e.toString());
//createDialog("Error", "Cannot Estabilish Connection");
}
}
}
);
Si prega di aiutare me Sono un novizio in JSON e l'analisi in Android.Thanx.
Grazie per la risposta per favore dimmi come passo new_member = come sto aggiungendo nell'URL ma l'url fornito è http://www.fourerr.com/ws/signup Dovrei prendere newmember come json oggetto.?? Per favore, aiutami .. –
che valore ha questo new_member? provare ad inviare come token è stato superato nell'esempio – Pratik
Si consiglia di utilizzare non ** StringEntity entity = new StringEntity (data.toString()); ** but ** StringEntity entity = new StringEntity (paramInput.toString(), HTTP.UTF_8); ** - Nel mio caso questo ha risolto il problema con la codifica di caratteri cirillici in json-string. – Prizoff