Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Volley库在PHP站点服务器上接收JSONObject?_Java_Php_Android_Post_Android Volley - Fatal编程技术网

Java 如何使用Volley库在PHP站点服务器上接收JSONObject?

Java 如何使用Volley库在PHP站点服务器上接收JSONObject?,java,php,android,post,android-volley,Java,Php,Android,Post,Android Volley,我尝试在PHP站点服务器上发送和接收JSONObject。我使用下面的示例代码 GlobalConfig config = new GlobalConfig(); JSONObject json = config.getConfig(); JSONObject data = new JSONObject(); try { data.put("ID", json.getString("ID")); data.put("session", json.getString("ses

我尝试在PHP站点服务器上发送和接收JSONObject。我使用下面的示例代码

GlobalConfig config = new GlobalConfig();
JSONObject json = config.getConfig();

JSONObject data = new JSONObject();

try {

    data.put("ID", json.getString("ID"));
    data.put("session", json.getString("session"));

} catch (JSONException e) {
    e.printStackTrace();
}


RequestQueue queue = Volley.newRequestQueue(this);

JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, PROT + "://" + REMOTE + "/" + DIR + "/test.php", data,
        new Response.Listener<JSONObject>()
        {
            @Override
            public void onResponse(JSONObject response) {
                // response

            }
        },
        new Response.ErrorListener()
        {
            @Override
            public void onErrorResponse(VolleyError error) {
                // error

            }
        }
);
GlobalConfig config=new GlobalConfig();
JSONObject json=config.getConfig();
JSONObject数据=新的JSONObject();
试一试{
data.put(“ID”,json.getString(“ID”);
data.put(“session”,json.getString(“session”);
}捕获(JSONException e){
e、 printStackTrace();
}
RequestQueue=Volley.newRequestQueue(this);
JsonObjectRequest postRequest=新的JsonObjectRequest(Request.Method.POST,PROT+“://“+REMOTE+”/“+DIR+”/test.php),数据,
新的Response.Listener()
{
@凌驾
公共void onResponse(JSONObject响应){
//回应
}
},
新的Response.ErrorListener()
{
@凌驾
公共无效onErrorResponse(截击错误){
//错误
}
}
);
下面是我的PHP脚本:

<?php

  $json = json_decode($_POST['json']);
  $date = date("Y-m-d H:i:s");

  $obj = new stdClass();
  $obj->id  = $json->ID;
  $obj->session = $json->session;

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "login: ".$obj->id.", ".session: ".$obj->session;
fwrite($myfile, $txt);
fclose($myfile);
?>