- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用无法从服务器获取数据。
我在互联网上找到的每个解决方案都不起作用。
private static final String KEY_DATA = "data";
HashMap<String, String> temp = new HashMap<>();
temp.put("nome",textoDigitado);
HttpJsonParser httpJsonParser = new HttpJsonParser();
JSONObject jsonObject = httpJsonParser.makeHttpRequest(BASE_URL+"fetch_single_bar.php","GET",temp);
JSONArray bares_json;
if (success == 1){
bares_json = jsonObject.getJSONArray(KEY_DATA);
}
W/System.err: org.json.JSONException: Value {"id":17,"nome":"bar teste","cidade":"cidade teste","estado":"estado teste","conectados":"0"} at data of type org.json.JSONObject cannot be converted to JSONArray
导航器中搜索的响应是:
{"success":1,"data":{"id":17,"nome":"bar teste","cidade":"cidade teste","estado":"estado teste","conectados":"0"}}
最佳答案
是的,您可以将JSONObject
解析为JSONArray
。但首先,使用 Volley 更容易获得响应(这是一个建议)。
您只需要做的是JSONArray array = (JSONArray) jsonObject.get("KEY_DATA");
。
jsonObject.get("KEY_DATA")
返回一个对象。
Volley 是一个异步库,它可以帮助您处理服务器响应,并且比我在其他库中看到的要容易得多。
关于java - JSONObject 无法转换为 JSONArray , jsonObject.getJSONArray(KEY_DATA) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57592421/
我正在使用网络服务请求直方图数据。数据是数组中的一组数组: [[1375056000000,23.284713745117],[1375142400000,3.809531211853], [1375
这是我的 json 文件的相关部分: "categories": [ [ "Belgian Restaurant", "belgian" ],
我目前很困惑,为什么我不能在我的 Android 应用程序中从 JSONArray 中提取 JSONArray。下面给出了一个示例和我的源代码片段。 //The JSON { "cur
我正在尝试解析 JSONObject。 这个 JSONObject 中有一个 JSONArray,它在 JSONArray 中还有另一个 JSONArray。 我试图解析的 json 形式如下。 {
我正在尝试解析对象数据列表中的 JSON 数组 payment_details。 在这里,我已经成功解析了回收站 View 中调用的数据数组,但我无法调用 payment_details 数组。 适配
我正在寻找一个选项,可以将多个值添加到 JSONArray 并将其添加到另一个 JSONArray 中,而无需创建多个变量。例如: JSONArray array1 = new JSONArr
我遇到过一种情况,org.json.JSONArray 对象非常大,这最终会导致延迟和其他问题。因此,我们决定将 JSONArray 分割成更小的 block 。例如,如果 JSONArray 是这样
您好,我正在尝试在另一个 json 数组中解析一个 json 数组。帮我解决这个问题。 我的 Json 数组是 "results":[ { "percentcompleted"
我正在使用 Gson用于解析 json 响应。我需要在 JsonArray 中解析 JSONArry.. 我的回答是.. { "message": "Retreive sucessfully", "f
@GET @Produces("application/json") public Response GetAll() throws JSONException{ tblCategoryDao
我从服务器获取以下 json: { "Data": [ { "Record": [ " d11", "d12"
我正在使用 ajax 将 json 对象从 javascript 传递到 java servlet。 var jsonObj = JSON.stringify(objArray); //Then I
我需要获取作为“结果”内部数组的“示例”数据 JSON FILE 并将其附加到字符串。最简单的方法是什么? 这就是我得到“定义”的方式 private JSONObject queryResults;
我需要从 JSONArray 获取 JSONArray: JSONParser parser = new JSONParser(); JSONObject jObject=(J
我有一个 jsonArray 响应。我需要阅读此响应,其中包含 3 个 jsonArray。 这是 json 响应。这是一个 GET 请求并通过 Volley 请求发送。 [ "0x9000",
在此 Json 响应中,如何使用 Java 访问“smallImageUrls”并获取图像 url? 似乎“smallImageUrls”是“匹配”jsonarray 中的一个数组。如果我错了,请有人
这个问题在这里已经有了答案: Convert string to JSON array (10 个答案) 关闭 5 年前。 如何正确地将此字符串转换为 jsonArray? { "myArr
是否可以从较新的 EJB JSON 库转换为较旧的 org.json 库,而无需依赖 org.json.simple 或 GSON? 在下面的例子中,“buttons”是一个填充的 JsonArr
如何从jsonarray获取jsonarray? 我试过的代码。 for(loop) List stringList = new ArrayLis
我目前是 Json 新手,遇到了一个问题。我搜索了很多但找不到答案! 我从 json url 获取名称列表。名称可以在此 json 文件中重复,但我只想将它们的一条记录保留到我称为“arr”的新数组中
我是一名优秀的程序员,十分优秀!