04-19 16:00:16.330: W/System.err(27629): org.json.JSONException: End of input at character 2 of
04-19 16:00:16.330: W/System.err(27629): at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
04-19 16:00:16.330: W/System.err(27629): at org.json.JSONTokener.nextValue(JSONTokener.java:97)
04-19 16:00:16.330: W/System.err(27629): at org.json.JSONArray.<init>(JSONArray.java:87)
04-19 16:00:16.330: W/System.err(27629): at org.json.JSONArray.<init>(JSONArray.java:103)
04-19 16:00:16.340: W/System.err(27629): at com.vtab.GetNetworkData.onPostExecute(GetNetworkData.java:95)
04-19 16:00:16.340: W/System.err(27629): at com.vtab.GetNetworkData.onPostExecute(GetNetworkData.java:1)
04-19 16:00:16.340: W/System.err(27629): at android.os.AsyncTask.finish(AsyncTask.java:602)
04-19 16:00:16.340: W/System.err(27629): at android.os.AsyncTask.access$600(AsyncTask.java:156)
04-19 16:00:16.340: W/System.err(27629): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
04-19 16:00:16.340: W/System.err(27629): at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 16:00:16.340: W/System.err(27629): at android.os.Looper.loop(Looper.java:137)
04-19 16:00:16.340: W/System.err(27629): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-19 16:00:16.340: W/System.err(27629): at java.lang.reflect.Method.invokeNative(Native Method)
04-19 16:00:16.340: W/System.err(27629): at java.lang.reflect.Method.invoke(Method.java:511)
04-19 16:00:16.350: W/System.err(27629): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-19 16:00:16.350: W/System.err(27629): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-19 16:00:16.350: W/System.err(27629): at dalvik.system.NativeStart.main(Native Method)
04-19 16:03:51.860: W/ThrottleService(167): unable to find stats for iface rmnet0
这是webservices函数
<php
function insert_order_item($order_id,$item_id,$quantity,$cat_id,$rest_id,$order_item_total)
{
mysql_connect("localhost","root","root");
mysql_select_db("myhoteldb");
$sql=mysql_query("INSERT INTO order_item (order_id,item_id,quantity,cat_id,rest_id,order_item_total_price)
VALUES($order_id,$item_id,$quantity,$cat_id,$rest_id,$order_item_total)");
mysql_close();
}
?>
这是android代码
public class GetNetworkData extends AsyncTask{
String uri;
private OnPostExecuteListener mPostExecuteListener = null;
public static interface OnPostExecuteListener
{
void onPostExecute(String result);
}
GetNetworkData(
String Url,
OnPostExecuteListener postExecuteListener) throws Exception {
uri = Url;
mPostExecuteListener = postExecuteListener;
if (mPostExecuteListener == null)
throw new Exception("Param cannot be null.");
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
JSONObject param=null;
String result = null;
HttpClient httpClient = new DefaultHttpClient();
HttpHost httpHost = new HttpHost("192.168.3.111",80);
HttpPost httpPost = new HttpPost(uri);
httpPost.addHeader("Content-Type", "application/json; charset=utf-8");
try
{
//HttpEntity bodyEntity = new StringEntity(param.toString(), "utf8");
//httpPost.setEntity(bodyEntity);
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(instream));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
sb.append(line + "\n");
result = sb.toString();
instream.close();
}
}
catch (Exception e) {
// TODO: handle exception
}
return result;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
if (mPostExecuteListener != null)
{
try {
JSONArray jArray = new JSONArray(result);
mPostExecuteListener.onPostExecute(result);
} catch (JSONException e){
e.printStackTrace();
}
}
}
}