1
|
JSONObject 的相关处理
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
//-------------遍历json串的key-----------
JSONObject data = JSONObject.fromObject(
"{\"cill\":\"2\",\"age\":\"黄磊\"}"
);
Iterator keys = data.keys();
ArrayList<String> listKey =
new
ArrayList<String>();
while
(keys.hasNext()) {
String key = keys.next().toString();
listKey.add(key);
}
//--------ArrayList转为String [ ] ---------
String[] array = (String[]) listKey.toArray(
new
String[listKey.size()]);
//-----string数组中的首字母排序 a- z 的顺序 ---------
// 调用数组的静态排序方法sort,且不区分大小写
Arrays.sort(array, String.CASE_INSENSITIVE_ORDER);
StringBuffer paramValue =
new
StringBuffer();
for
(String key : array) {
String value = data.getString(key);
paramValue.append(value);
}
//-----json数据中删除一个元素 ---------
jsonObject.remove(
"key"
);
//-----创建数组的三种方式---------
public
static
void
main(String[] args){
//第一种
int
[] temp = {
3
,
5
,
6
,
7
,
9
,
4
,
1
,
21
,
36
,
0
};
//第二种
int
[] temp1 =
new
int
[
3
];
temp1[
0
]=
1
;
temp1[
1
]=
1
;
temp1[
2
]=
1
;
//第三种
int
vec[] =
new
int
[]{
1
,
5
,
3
};
}
本文转自建波李 51CTO博客,原文链接:http://blog.51cto.com/jianboli/1889497,如需转载请自行联系原作者
|