2 回答

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
public @ResponseBody Map<String, String> categor() {
Map<String, String> data = new HashMap<String, String>();
List<ProductCategory> list = productCategoryService.findRoots();
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
jsonConfig.setExcludes(new String[]{//只要設(shè)置這個(gè)數(shù)組,指定過濾哪些字段。
"children",
"products",
"brands",
"parameterGroups",
"promotions",
"attributes"
});
JSONArray jsonObjectFromMap = JSONArray.fromObject(list,jsonConfig);
data.put("rootProductCategories", jsonObjectFromMap.toString());
return data;
}
擴(kuò)展資料
JSON對象是直接可以使用JQuery操作的格式,如C#中可以用對象(類名)點(diǎn)出屬性(方法)一樣
JSON字符串僅僅只是一個(gè)字符串,一個(gè)整體,不截取的話沒辦法取出其中存儲(chǔ)的數(shù)據(jù),不能直接使用,除非你只想alert()他;
- 2 回答
- 0 關(guān)注
- 544 瀏覽
添加回答
舉報(bào)