猿问

json字符串怎转换成json对象?

例如:有这样的字符串[{"CityId":18,"CityName":"西安","ProvinceId":27,"CityOrder":1},{"CityId":53,"CityName":"广州","ProvinceId":27,"CityOrder":1}],用js转换成json对象,请高手指导

凤凰求蛊
浏览 503回答 2
2回答

料青山看我应如是

public&nbsp;@ResponseBody&nbsp;Map<String,&nbsp;String>&nbsp;categor()&nbsp;{&nbsp;&nbsp;Map<String,&nbsp;String>&nbsp;data&nbsp;=&nbsp;new&nbsp;HashMap<String,&nbsp;String>();&nbsp;&nbsp;List<ProductCategory>&nbsp;list&nbsp;=&nbsp;productCategoryService.findRoots();&nbsp;&nbsp;JsonConfig&nbsp;jsonConfig&nbsp;=&nbsp;new&nbsp;JsonConfig();&nbsp;&nbsp;jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);&nbsp;&nbsp;jsonConfig.setExcludes(new&nbsp;String[]{//只要设置这个数组,指定过滤哪些字段。&nbsp;&nbsp;"children",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"products",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"brands",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"parameterGroups",&nbsp;&nbsp;"promotions",&nbsp;&nbsp;&nbsp;"attributes"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JSONArray&nbsp;jsonObjectFromMap&nbsp;=&nbsp;JSONArray.fromObject(list,jsonConfig);&nbsp;&nbsp;data.put("rootProductCategories",&nbsp;jsonObjectFromMap.toString());&nbsp;&nbsp;return&nbsp;data;&nbsp;&nbsp;}&nbsp;&nbsp;扩展资料JSON对象是直接可以使用JQuery操作的格式,如C#中可以用对象(类名)点出属性(方法)一样JSON字符串仅仅只是一个字符串,一个整体,不截取的话没办法取出其中存储的数据,不能直接使用,除非你只想alert()他;
随时随地看视频慕课网APP
我要回答