- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建类,该类应使用带有特定参数的 volley 发送 JSONArrayRequest
,然后找到等于这些参数的 mysql
行并将其发回。我编写了简单的 mysql
函数来接收 POST
参数和发送和接收 JSONObjects
的 Java 方法。但它不起作用,我什么也没收到。
这是我的 PHP 文件,名为 details.php
。它从我的 Android 应用程序接收参数并发回一个数组。
require_once __DIR__ . '/db_connect.php'
$db = new DB_CONNECT();
$path= $_POST["path"];
$result = mysql_query("SELECT * FROM modx_ms2_product_files WHERE path = $path") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$json_response = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product ["file"] = $row["file"];
// push single product into final response array
array_push($json_response, $product);
}
// echoing JSON response
echo json_encode($json_response);
$conn->close();
}
这是我的方法 getArray()
,它发送请求并接收响应:
public void getarray() {
String path = "1578/";
final String URL = "http://myurl.io/details.php";
HashMap<String, String> params = new HashMap<String, String>();
params.put("path", path);
JsonArrayRequest customarray = new JsonArrayRequest(Request.Method.POST,URL,new JSONObject(params),new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
if (response.length() > 0) {
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject Obj = response.getJSONObject(i);
pics pic = new pics();
pic.setFile(Obj.getString("file"));
Log.i("cmon", Obj.getString("file"));
pics.add(pic);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
AppController.getInstance().addToRequestQueue(customarray);
}
这是我的modx_ms2_product_files
表:
最佳答案
您是否尝试过使用 StringRequest
?出于某种原因,当我使用 JsonArrayRequest
时,我没有从服务器收到任何响应。如果您决定创建一个 StringRequest
,您可以将您的响应转换为一个 JSONArray
,如下所示:
StringRequest get = new StringRequest(Method.POST, URL, new Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray myArray = new JSONArray(response);
for(int i = 0; i < myArray.length(); i++)
{
JSONObject jObj = myArray.getJSONObject(i);
// get your data here
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
然后当然将您的请求添加到请求队列中。
关于java - JSONArrayRequest 和 PHP 对不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31368206/
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我制作 jsonArrayRequest 的函数内容是: JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Me
我试图根据我发送的数据从服务器获取响应,我能够从服务器获取响应,但服务器似乎没有接收 getParams() 中的值。 String url = "myUrl"; Req
我已经尝试使用普通的 JSONArrayRequests 和 StringRequests,直到现在一切都很好。我想发送一个带有 POST 参数的 JSONArrayRequest 以从脚本中获取一些
我是 Volley 的新手,我正在尝试让 Post 请求与 一起工作 JsonArrayRequest 从我在 stackoverflow 上找到的许多答案中,我尝试如下 - private
请帮助我(我不明白问题是什么。它给出了一个错误和文本“ERROR”,我在日志中找不到任何内容。我是初学者,目前正在学习 android 开发。 RequestQueue requestQueu
我正在创建类,该类应使用带有特定参数的 volley 发送 JSONArrayRequest,然后找到等于这些参数的 mysql 行并将其发回。我编写了简单的 mysql 函数来接收 POST 参数和
我从向我的服务器发送参数时收到一个错误,好像我的参数根本没有传递到我的服务器...我得到的是: D/Searching: Error: org.json.JSONException: Value {"
我已经尝试了一些关于将帖子从 JsonArrayRequest volley 发送到服务器的示例,但它不起作用并且日志中没有错误.. 所以当我在服务器中调用一个帖子时,帖子无法获取并且在不调用帖子时显
我正在尝试使用 volley 发出 post 请求。 请求参数是一个json数组。 以下是我的请求参数 [ "Type", { "User": "email", "password": "
我知道使用 JsonArrayRequest 的 POST 请求在 Volley 中不可用,但我看到这篇文章 here那谈到了添加一个构造函数来处理这个问题。他们的实现是这样的: public Jso
我是一名编程学生,正在构建一个使用 api json url 的 Android 应用程序,但我找不到适合 JsonArrayRequest 的构造函数 这是错误: C:\Users\jerma\An
我是 Json 解析的新手。我正在尝试使用 JsonArrayRequest 读取 json 数据,但我对发送参数和使用 POST 方法有点困惑。在 JsonObjectRequest 的情况下,我可
所以我看到了几个 JsonObjectRequests 的例子,其中添加了这段代码 @Override public String getBodyContentType
我正在尝试在 fragment 中调用带有 spinner.setOnItemSelectedListener 的 JsonArrayRequest。但它在这一行给我错误 RequestQueue r
我正在使用 Volley与 API 互动.我需要将带有参数的发布请求发送到返回 JSONArray 的服务. 我正在覆盖方法 protected Map getParams()但它不起作用: Json
我需要使用 JSONObject 发出请求,如下所示: { 'LangIDs': [1, 2], 'GenreIDs': [4], 'LowPrice': 0, 'Hi
使用android studio,我尝试使用JsonArrayRequest和Post方法获取JsonArray,但它不起作用(POST方法发送一个空字符串),所以我使用了StringRequest,
我正在使用 Volley 访问 REST API。我的大多数调用都返回 200,如果它返回 400、401 或 409,我将返回一个 json 响应,其中包含关于错误信息的不同错误消息。我一直在查看
从昨天开始我就一直遇到这个问题,从我的服务器获取数据。我在 POSTMAN 中测试我的 php 代码并将格式更改为 JSON,我什至在 JSONLint 上测试它并且它返回有效的 json。我注意到它
我是一名优秀的程序员,十分优秀!