简体   繁体   中英

how can i access json object in javascript and convert it into array in java?

In controller class, I am sending one json object (data) how can i access it in javascript? and i want it to be converted into array containing object

 @RequestMapping("/piechart")
public String getChartDetails(Map<String, Object> model) throws                   Exception{
    List<ChartEntry> chartEntries =chartService.getChartEntryCounts();
    ChartData data = new ChartData();
    data.setChartEntry(chartEntries);
    model.put("data", Resources.objectAsJson(data));

    return "/analyticsChart";

Assuming you are using JSP for view part.

There is one possibility You can assign your model object to a javascript variable as

<script type= "text/javascript">
var response = ${data};
</script> 

Now you can use this Javascript response object as your wish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM