我必须在以下URL数据发送到web服务如何使用JSON将数据发布到Web服务?
要被发送的数据的格式是:
new_member=[{"email":"[email protected]","username":"himanshu01","pwd":"himanshu01"}]
其中email
,username
和pwd
是关键,并且具有相应的值的字符串通过的EditText取出串。我点击按钮发布这些数据。
我没有得到任何回应bcoz我试图反击检查与我的合作开发人员在他的iPhone相同的应用程序iPhone版的用户名和密码无效是由服务器说。
我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");
}
}
}
);
请帮助我,我在JSON一个新手和Android.Thanx解析。
Thanx的答复,请告诉我我是如何通过new_member =因为我追加在网址,但实际提供的网址是http://www.fourerr.com/ws/signup我应该把新会员作为JSON目的。??请帮助我.. – 2011-12-15 12:52:25