ui-app中如何将{ "provinceCode": "230000", "provinceName": "黑龙江省", "cityCode": "230300"}数据转化为数组
时间: 2023-10-02 12:12:05 浏览: 82
您可以使用`Object.values()`方法将对象的值转化为数组。首先,您需要将给定的数据对象保存到一个变量中,然后使用`Object.values()`方法将其转化为数组。
以下是将{ "provinceCode": "230000", "provinceName": "黑龙江省", "cityCode": "230300"}数据转化为数组的示例代码:
```javascript
const data = { "provinceCode": "230000", "provinceName": "黑龙江省", "cityCode": "230300"};
const dataArray = Object.values(data);
console.log(dataArray);
```
输出结果:
```javascript
["230000", "黑龙江省", "230300"]
```
相关问题
// 省集合 let ps = pca.filter(d => !d.provinceCode && !d.cityCode); // 市集合 let cs = pca.filter(d => d.provinceCode && !d.cityCode); // 区集合 let as = pca.filter(d => d.cityCode); // 目标数据: 省市区父子关系树形数据 let list = ps.map(p => ({ ...p, label: p.name, value: p.name, children: cs.map(c => ({ ...c, label: c.name, value: c.name, children: as.filter(a => a.cityCode.toString() == c.code), // 从市过滤出区 })).filter(c => c.provinceCode == p.code), // 从省过滤出市 })); console.log(list);转java代码
以下是将 JavaScript 代码转化为 Java 代码的示例:
```java
// 省集合
List<Place> ps = pca.stream().filter(d -> d.provinceCode == null && d.cityCode == null).collect(Collectors.toList());
// 市集合
List<Place> cs = pca.stream().filter(d -> d.provinceCode != null && d.cityCode == null).collect(Collectors.toList());
// 区集合
List<Place> as = pca.stream().filter(d -> d.cityCode != null).collect(Collectors.toList());
// 目标数据: 省市区父子关系树形数据
List<Map<String, Object>> list = ps.stream().map(p -> {
Map<String, Object> map = new HashMap<>();
map.put("name", p.getName());
map.put("label", p.getName());
map.put("value", p.getName());
map.put("children", cs.stream().filter(c -> c.getProvinceCode() == p.getCode()).map(c -> {
Map<String, Object> map1 = new HashMap<>();
map1.put("name", c.getName());
map1.put("label", c.getName());
map1.put("value", c.getName());
map1.put("children", as.stream().filter(a -> a.getCityCode().toString().equals(c.getCode())).map(a -> {
Map<String, Object> map2 = new HashMap<>();
map2.put("name", a.getName());
map2.put("label", a.getName());
map2.put("value", a.getName());
return map2;
}).collect(Collectors.toList()));
return map1;
}).collect(Collectors.toList()));
return map;
}).collect(Collectors.toList());
System.out.println(list);
```
该代码使用了 Java 8 的 Lambda 表达式和流式 API 实现了与 JavaScript 代码相同的逻辑。需要注意的是,Java 中的集合和数组的访问方式与 JavaScript 不同,需要根据具体的对象结构进行修改。
Java获取{ "retCode": "000000", "retDesc": "成功", "data": { "pageNo": 1, "pageSize": 500, "count": 12712, "totalPage": 26, "first": 0, "last": 0, "prev": 0, "next": 0, "firstPage": false, "lastPage": false, "list": [ { "orgaCodeName": "学校标识码", "recommendUseCount": 0, "areaName": "安徽省", "provinceCode": "340000", "orgaId": "34d8a1b4b51b434998a1b4b51b034954", "orgaCode": "12341203MB1J665277", "zyappCount": 0, "orgaName": "颍东区向阳小学", "orgaLogo": "", "askUseCount": 0 }, { "orgaCodeName": "学校标识码", "recommendUseCount": 0, "areaName": "安徽省", "provinceCode": "340000", "orgaId": "9e68dc5aa2b441b4a8dc5aa2b401b4fc", "orgaCode": "12340207MB1H12340F", "zyappCount": 0, "orgaName": "芜湖市皖江小学", "orgaLogo": "", "askUseCount": 0 } ] } }json串中的所有orgaName
您可以使用以下代码来获取json串中的所有orgaName:
import org.json.JSONArray;
import org.json.JSONObject;
public class Main {
public static void main(String[] args) {
String jsonStr = "{\"retCode\":\"000000\",\"retDesc\":\"成功\",\"data\":{\"pageNo\":1,\"pageSize\":500,\"count\":12712,\"totalPage\":26,\"first\":0,\"last\":0,\"prev\":0,\"next\":0,\"firstPage\":false,\"lastPage\":false,\"list\":[{\"orgaCodeName\":\"学校标识码\",\"recommendUseCount\":0,\"areaName\":\"安徽省\",\"provinceCode\":\"340000\",\"orgaId\":\"34d8a1b4b51b434998a1b4b51b034954\",\"orgaCode\":\"12341203MB1J665277\",\"zyappCount\":0,\"orgaName\":\"颍东区向阳小学\",\"orgaLogo\":\"\",\"askUseCount\":0},{\"orgaCodeName\":\"学校标识码\",\"recommendUseCount\":0,\"areaName\":\"安徽省\",\"provinceCode\":\"340000\",\"orgaId\":\"9e68dc5aa2b441b4a8dc5aa2b401b4fc\",\"orgaCode\":\"12340207MB1H12340F\",\"zyappCount\":0,\"orgaName\":\"芜湖市皖江小学\",\"orgaLogo\":\"\",\"askUseCount\":0}]}}";
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray orgaList = jsonObj.getJSONObject("data").getJSONArray("list");
for (int i = 0; i < orgaList.length(); i++) {
String orgaName = orgaList.getJSONObject(i).getString("orgaName");
System.out.println(orgaName);
}
}
}
这段代码将输出以下内容:
颍东区向阳小学
芜湖市皖江小学
希望这能帮到您!
阅读全文