- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 android 的新手,我以前使用的是从服务器获取 JSON 数组并解析 JSON 对象,如下所示,
JSONObject objResponse = new JSONObject(retResult);
String objString = objResponse.toString();
String strResponse = null;
if ((objString.contains(getString(R.string.response)))
|| objString.contains((String) getString(R.string.response)
.toLowerCase())
|| (objString.contains((String) getString(R.string.response)
.toUpperCase()))) {
strResponse = objResponse.getString(getString(R.string.response));
} else {
strResponse = "";
}
帮我解析一下从服务器返回的JSON,,,
{
"iapStandardHeight":[
[
53.4,
65.3,
71.6,
76.2,
80.2,
83.9,
87.3,
90.5,
93.6,
95.7,
98.3,
100.8,
103.1,
107.3,
111.2,
115,
118.7,
125.9,
129.2,
132.3,
135.6,
138.9,
142.1,
145,
147.7,
150.4,
153.2,
156.3,
159.8,
163.4,
167,
170.6,
174.1,
177,
179.1,
180.6,
181.5,
182.1,
182.6,
182.9,
183.1,
183.3
],
[
51.2,
62.8,
69.1,
73.5,
77.4,
80.9,
84.1,
87.1,
89.9,
91.8,
94.2,
96.5,
98.6,
102.5,
106.2,
109.6,
113.1,
118.5,
121.6,
124.6,
127.7,
130.8,
133.8,
136.6,
139.1,
141.6,
144.2,
147,
150.2,
153.4,
156.7,
160.1,
163.6,
166.7,
169.2,
171,
172.3,
173.1,
173.7,
174.2,
174.5,
174.7
],
[
49.9,
61.4,
67.6,
72,
75.7,
79.1,
82.3,
85.1,
87.8,
89.6,
91.9,
94.1,
96.1,
99.9,
103.3,
106.7,
110,
114.9,
118,
120.9,
123.9,
126.9,
129.8,
132.4,
134.9,
137.2,
139.7,
142.4,
145.3,
148.3,
151.5,
154.8,
158.2,
161.4,
164.1,
166.1,
167.5,
168.5,
169.2,
169.7,
170,
170.4
],
[
48.6,
60.1,
66.2,
70.5,
74.1,
77.4,
80.4,
83.2,
85.8,
87.4,
89.6,
91.7,
93.6,
97.2,
100.5,
103.7,
106.8,
111.4,
114.4,
117.2,
120.1,
123,
125.7,
128.3,
130.6,
132.9,
135.2,
137.7,
140.5,
143.3,
146.2,
149.4,
152.8,
156,
158.9,
161.1,
162.7,
163.8,
164.6,
165.1,
165.5,
165.9
],
[
46.3,
57.6,
63.6,
67.7,
71.3,
74.4,
77.2,
79.7,
82.1,
83.5,
85.5,
87.4,
89.1,
92.4,
95.4,
98.4,
101.2,
104.7,
107.5,
110.1,
112.7,
115.4,
117.9,
120.1,
122.2,
124.3,
126.3,
128.4,
130.8,
133.1,
135.6,
138.5,
141.7,
145.1,
148.2,
150.8,
152.8,
154.1,
155.1,
155.8,
156.3,
156.7
]
],
"iapStandardWeight":[
[
4.3,
7.9,
9.7,
10.9,
11.8,
12.7,
13.5,
14.3,
15.1,
15.9,
16.6,
17.3,
18,
19.4,
20.9,
22.3,
28.6,
31.3,
33.9,
36.6,
39.4,
42.5,
45.8,
48.8,
51.8,
54.8,
57.9,
61.4,
65.3,
69.1,
72.8,
76.5,
80.2,
83.6,
86.8,
89.4,
91.6,
93.4,
94.9,
96.2,
97.3,
98.3
],
[
3.7,
6.9,
8.5,
9.6,
10.4,
11.1,
11.8,
12.5,
13.1,
13.8,
14.4,
15,
15.6,
16.7,
17.8,
19,
20.8,
22.5,
24.1,
25.8,
27.5,
29.4,
31.5,
33.4,
35.3,
37.3,
39.5,
42.1,
45,
47.9,
50.9,
53.8,
56.7,
59.4,
61.8,
63.9,
65.6,
67,
68.2,
69.2,
70.1,
71
],
[
3.3,
6.4,
7.9,
8.9,
9.6,
10.3,
10.9,
11.5,
12.2,
12.7,
13.3,
13.8,
14.3,
15.3,
16.3,
17.3,
18.4,
19.8,
21.1,
22.5,
23.9,
25.4,
27,
28.6,
30.1,
31.7,
33.5,
35.6,
38,
40.5,
43,
45.6,
48.1,
50.6,
52.8,
54.7,
56.3,
57.7,
58.8,
59.8,
60.7,
61.5
],
[
3,
5.9,
7.4,
8.3,
9,
9.6,
10.1,
10.7,
11.3,
11.8,
12.3,
12.8,
13.2,
14.1,
15,
15.9,
16.5,
17.7,
18.8,
19.9,
21.1,
22.3,
23.6,
24.9,
26.1,
27.3,
28.8,
30.4,
32.4,
34.4,
36.6,
38.8,
41,
43.3,
45.4,
47.2,
48.8,
50.1,
51.2,
52.1,
53.1,
53.9
],
[
2.5,
5.1,
6.4,
7.2,
7.8,
8.4,
8.9,
9.3,
9.8,
10.2,
10.7,
11.1,
11.4,
12.2,
12.9,
13.6,
13.8,
14.7,
15.5,
16.2,
17,
17.9,
18.7,
19.5,
20.3,
21.1,
21.9,
22.9,
24.2,
25.5,
26.9,
28.5,
30.3,
32.2,
34.1,
35.8,
37.3,
38.6,
39.7,
40.7,
41.6,
42.5
]
],
"iapStandardAgeDiff":[
"0.0",
"0.3",
"0.6",
"0.9",
"1.0",
"1.3",
"1.6",
"1.9",
"2.0",
"2.3",
"2.6",
"2.9",
"3.0",
"3.6",
"4.0",
"4.6",
"5.0",
"6.0",
"6.6",
"7.0",
"7.6",
"8.0",
"8.6",
"9.0",
"9.6",
"10.0",
"10.6",
"11.0",
"11.6",
"12.0",
"12.6",
"13.0",
"13.6",
"14.0",
"14.6",
"15.0",
"15.6",
"16.0",
"16.6",
"17.0",
"17.6",
"18.0"
],
"gender":"Boys",
"dob":"2000/2/5",
"IAPDetails":{
"heightInCms":[
152.401853206535
],
"heightInFt":[
5
],
"heightInCmsDate":[
"2014/1/25"
],
"heightInFtDate":[
"2014/1/25"
],
"weightInKg":[
45
],
"weightInLbs":[
99.20799000000001
],
"weightInKgDate":[
"2014/1/25"
],
"weightInLbsDate":[
"2014/1/25"
]
},
"response":"success"
}
帮助将不胜感激
最佳答案
属性 iapStandardHeight
看起来是一个锯齿状的数组。这看起来是您收到的 json 中最复杂的部分。下面是用于从您发布的 json 创建锯齿状双数组的代码。如果您需要更多帮助,只需添加评论即可。
JSONObject jsonResponse = new JSONObject(response);
JSONArray outerArray = jsonResponse.getJSONArray("iapStandardHeight");
double[][] result = new double[outerArray.length()][];
for(int i = 0; i < outerArray.length(); i++){
JSONArray innerArray = outerArray.getJSONArray(i);
double[] innerResult = new double[innerArray.length()];
for(int j = 0; j < innerArray.length(); j++){
innerResult[j] = innerArray.getDouble(j);
}
result[i] = innerResult;
}
关于android - 在android中的JSON数组中解析double[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22014526/
最近开始学习MongoDB。今天老师教了我们 mongoexport 命令。在练习时,我遇到了一个典型的问题,包括教练在内的其他同学都没有遇到过。我在我的 Windows 10 机器上使用 Mongo
我是 JSON Schema 的新手,读过什么是 JSON Schema 等等。但我不知道如何将 JSON Schema 链接到 JSON 以针对该 JSON Schema 进行验证。谁能解释一下?
在 xml 中,我可以在另一个 xml 文件中包含一个文件并使用它。如果您的软件从 xml 获取配置文件但没有任何方法来分离配置,如 apache/ngnix(nginx.conf - site-av
我有一个 JSON 对象,其中包含一个本身是 JSON 对象的字符串。我如何反序列化它? 我希望能够做类似的事情: #[derive(Deserialize)] struct B { c: S
考虑以下 JSON { "a": "{\"b\": 12, \"c\": \"test\"}" } 我想定义一个泛型读取 Reads[Outer[T]]对于这种序列化的 Json import
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 11 个月前关闭。 Improve
我的旧项目在 MySQL 中有 Standard JSON 格式的数据。 对于我在 JS (Node.js) 和 DynamoDB 中的全新项目,关于 Standard JSON格式: 是否建议将其转
JSON 值字符串、数字、true、false、null 是否是有效的 JSON? 即,是 true 一个有效的 JSON 文档?还是必须是数组/对象? 一些验证器接受这个(例如 http://jso
我有一个 JSON 字符串,其中一个字段是文本字段。这个文本字段可以包含用户在 UI 中输入的文本,如果他们输入的文本是 JSON 文本,也许是为了说明一些编码,我需要对他们的文本进行编码,以便它不会
我正在通过 IBM MQ 调用处理数据,当由 ColdFusion 10 (10,0,11,285437) 序列化时,0 将作为 +0.0 返回,它会导致无效的 JSON并且无法反序列化。 stPol
我正在从三个数组中生成一个散列,然后尝试构建一个 json。我通过 json object has array 成功了。 require 'json' A = [['A1', 'A2', 'A3'],
我从 API 接收 JSON,响应可以是 30 种类型之一。每种类型都有一组唯一的字段,但所有响应都有一个字段 type 说明它是哪种类型。 我的方法是使用serde .我为每种响应类型创建一个结构并
我正在下载一个 JSON 文件,我已将其检查为带有“https://jsonlint.com”的有效 JSON 到文档目录。然后我打开文件并再次检查,结果显示为无效的 JSON。这怎么可能????这是
我正在尝试根据从 API 接收到的数据动态创建一个 JSON 对象。 收到的示例数据:将数据解码到下面给出的 CiItems 结构中 { "class_name": "test", "
我想从字符串转换为对象。 来自 {"key1": "{\n \"key2\": \"value2\",\n \"key3\": {\n \"key4\": \"value4\"\n }\n
目前我正在使用以下代码将嵌套的 json 转换为扁平化的 json: import ( "fmt" "github.com/nytlabs/gojsonexplode" ) func
我有一个使用来自第三方 API 的数据的应用程序。我需要将 json 解码为一个结构,这需要该结构具有“传入”json 字段的 json 标签。传出的 json 字段具有不同的命名约定,因此我需要不同
我想使用 JSON 架构来验证某些值。我有两个对象,称它们为 trackedItems 和 trackedItemGroups。 trackedItemGroups 是组名称和 trackedItem
考虑以下案例类模式, case class Y (a: String, b: String) case class X (dummy: String, b: Y) 字段b是可选的,我的一些数据集没有字
我正在存储 cat ~/path/to/file/blah | 的输出jq tojson 在一个变量中,稍后在带有 JSON 内容的 curl POST 中使用。它运作良好,但它删除了所有换行符。我知
我是一名优秀的程序员,十分优秀!