我想向我的数据库表发布游戏高分,但我无法弄清楚如何通过传递整数值,只有字符串来做到这一点。以下是我在游戏结束时要调用的方法,这应该将分数插入到我的表的分数列中。在Android上使用nameValuePairs通过HTTP发布整数值
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://deucalion0.co.uk/insert.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("score", finalscore)); //"score" is the name of the database table, finalscore is the integer that contains the value
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
我正在下的参数“分数”一条红线,finalscore因为它告诉我,它只能拿一个字符串,它知道最后的比分是一个整数。
如果我能想出来,我将创建一种方法,用户可以通过表单输入输入名称,并将其与分数一起输入表格的用户列。我已经通过Stackoverflow搜索整数和nameValuePairs的帮助,但找不到任何东西。
我很感激任何帮助。
谢谢。
你还没有提到你所发布的代码遇到的任何特定错误。什么不按照你想要的方式工作? – Argyle 2012-03-05 22:16:32