I am beginner in Android. In my Project, I am getting the Following json from the HTTP Response.

[{"Date":"2012-1-4T00:00:00",
"keywords":null,
"NeededString":"this is the sample string I am needed for my project",
"others":"not needed"}]

I want to get the "NeededString" from the above json. How to get it?

推荐答案

这可能对你有帮助.

Java:

JSONArray arr = new JSONArray(result);
JSONObject jObj = arr.getJSONObject(0);
String date = jObj.getString("NeededString");

100

val jsonArray = JSONArray(result)
val jsonObject: JSONObject = jsonArray.getJSONObject(0)
val date= jsonObject.get("NeededString")
  • getJSONObject(Index).在上面的示例中,0表示索引.

Json相关问答推荐

为什么 Django Rest API 序列化器没有正确序列化多对多字段

在 PowerShell 中通过 aws cli 创建 cloudwatch alert 时出现字符串解析错误

Jolt 不打印任何东西

Groovy JsonBuilder 在for循环中添加数组元素

如何修复通过在 tsconfig.json 文件中添加allowImportingTsExtensions引发的错误 TS5023?

使用本地 JSON api react TS Axios

数据清理设计不良的 JSON 数据 - 需要有关最佳策略的建议

每次在 SoapUI 中发送请求时,将 JSON 响应的子 node 分配给项目变量

如何使用nifi从json文件中过滤属性

如何使用 Google 表格应用程序脚本将 JSON 中的多个字段提取到 Google 表格中

在 rust 中从 API 反序列化 serde_json

当值包含ansible中的字符串时解析json值

使用基本身份验证通过 CURL 发布 JSON

在 JSON API Wordpress 上启用 CORS

json和空数组

在 HTML 数据属性上添加 JSON 是不是很糟糕?

杰克逊在通用列表中读取 json

Volley JsonObjectRequest Post 参数不再起作用

类型是接口或抽象类,不能实例化

如何对 Javascript 对象进行排序,或将其转换为数组?