The Java background json is sent to the foreground;

Keywords: JSON Session Java

This is the case:

//Convert java object to json string and put it into session
String jsonMenu =JSONObject.fromObject(sysMenu).toString();
session.setAttribute("sysMenu",jsonMenu );

Then the foreground gets the json object from the session and binds the data to the corresponding container.
However, it is suddenly found that the expected binding is not successful, and then the json object obtained in the lower foreground is output in the browser console. It is found that it turns into this:

{"msg":"OK","data":[{"resourceId":"0","resurl":"","flag":"1","isParent":0,"icon":"","description":"","sort":1,"resname":"System setup","type":"0","parentId":"","rescode":"menu","cdate":{"date":20,"hours":21,"seconds":48,"month":7,"timezoneOffset":-480,"year":118,"minutes":11,"time":1534770708000,"day":1},"mdate":{"date":20,"hours":21,"seconds":50,"month":7,"timezoneOffset":-480,"year":118,"minutes":11,"time":1534770710000,"day":1},"sysResources":[{"resourceId":"1","resurl":"/admin/sysUser","flag":"1","isParent":0,"icon":"","description":"user","sort":1,"resname":"user management","type":"1","parentId":"0","rescode":"sysUser-list","cdate":{"date":20,"hours":21,"seconds":8,"month":7,"timezoneOffset":-480,"year":118,"minutes":43,"time":1534772588000,"day":1},"mdate":{"date":5,"hours":0,"seconds":32,"month":7,"timezoneOffset":-480,"year":118,"minutes":53,"time":1533401612000,"day":0},"sysResources":[]},{"resourceId":"2","resurl":"/admin/sysRole","flag":"1","isParent":0,"icon":"","description":"role","sort":2,"resname":"Role management","type":"1","parentId":"0","rescode":"sysRole-list","cdate":{"date":20,"hours":21,"seconds":14,"month":7,"timezoneOffset":-480,"year":118,"minutes":12,"time":1534770734000,"day":1},"mdate":{"date":5,"hours":0,"seconds":43,"month":7,"timezoneOffset":-480,"year":118,"minutes":53,"time":1533401623000,"day":0},"sysResources":[]},{"resourceId":"3","resurl":"/admin/sysResource","flag":"1","isParent":0,"icon":"","description":"Jurisdiction","sort":3,"resname":"Privilege management","type":"1","parentId":"0","rescode":"sysResource-list","cdate":{"date":20,"hours":21,"seconds":18,"month":7,"timezoneOffset":-480,"year":118,"minutes":12,"time":1534770738000,"day":1},"mdate":{"date":5,"hours":0,"seconds":59,"month":7,"timezoneOffset":-480,"year":118,"minutes":53,"time":1533401639000,"day":0},"sysResources":[]},{"resourceId":"8142A1BC54E345BF99095847E8D17E66","resurl":"/admin/sysLog","flag":"1","isParent":0,"icon":"ss","description":"Journal","sort":4,"resname":"Log management","type":"1","parentId":"0","rescode":"sysLog-list","cdate":{"date":22,"hours":20,"seconds":19,"month":7,"timezoneOffset":-480,"year":118,"minutes":33,"time":1534941199000,"day":3},"mdate":{"date":22,"hours":20,"seconds":19,"month":7,"timezoneOffset":-480,"year":118,"minutes":33,"time":1534941199000,"day":3},"sysResources":[]},{"resourceId":"E13A6C41CE3B42468AFAE57D7BBC2F20","resurl":"/admin/appUser","flag":"1","isParent":0,"icon":"nothing","description":"app user management","sort":20,"resname":"app user management","type":"1","parentId":"0","rescode":"appUser-list","cdate":null,"mdate":{"date":27,"hours":15,"seconds":38,"month":7,"timezoneOffset":-480,"year":118,"minutes":54,"time":1535356478000,"day":1},"sysResources":[]}]},{"resourceId":"F901703D395D4BDEBC739BB56D48EE5B","resurl":"","flag":"1","isParent":0,"icon":"menu","description":"Integrated services","sort":2,"resname":"Integrated services","type":"0","parentId":"","rescode":"menu","cdate":{"date":23,"hours":11,"seconds":26,"month":7,"timezoneOffset":-480,"year":118,"minutes":29,"time":1534994966000,"day":4},"mdate":{"date":23,"hours":11,"seconds":26,"month":7,"timezoneOffset":-480,"year":118,"minutes":29,"time":1534994966000,"day":4},"sysResources":[{"resourceId":"24C5B73EA9F0400EA47EE35CEE6383C8","resurl":"/admin/sysBlog","flag":"1","isParent":0,"icon":"Log management","description":"Log management","sort":12,"resname":"Log management","type":"1","parentId":"F901703D395D4BDEBC739BB56D48EE5B","rescode":"sysBlog-list","cdate":null,"mdate":{"date":28,"hours":11,"seconds":37,"month":7,"timezoneOffset":-480,"year":118,"minutes":49,"time":1535428177000,"day":2},"sysResources":[]},{"resourceId":"50C5E3BBC2B24EBBB921260F6C57D7DF","resurl":"/admin/appTopic","flag":"1","isParent":0,"icon":"appTopic","description":"Topic management","sort":27,"resname":"Topic management","type":"1","parentId":"F901703D395D4BDEBC739BB56D48EE5B","rescode":"appTopic-list","cdate":{"date":27,"hours":14,"seconds":27,"month":7,"timezoneOffset":-480,"year":118,"minutes":32,"time":1535351547000,"day":1},"mdate":{"date":27,"hours":14,"seconds":27,"month":7,"timezoneOffset":-480,"year":118,"minutes":32,"time":1535351547000,"day":1},"sysResources":[]},{"resourceId":"64AEEA6955454A52BDBCB56092346F05","resurl":"/admin/sysCarousel","flag":"1","isParent":0,"icon":"Wheel planting/Advertising management","description":"Wheel planting/Advertising management","sort":12,"resname":"Wheel planting/Advertising management","type":"1","parentId":"F901703D395D4BDEBC739BB56D48EE5B","rescode":"sysCarousel-list","cdate":{"date":28,"hours":20,"seconds":58,"month":7,"timezoneOffset":-480,"year":118,"minutes":53,"time":1535460838000,"day":2},"mdate":{"date":28,"hours":20,"seconds":58,"month":7,"timezoneOffset":-480,"year":118,"minutes":53,"time":1535460838000,"day":2},"sysResources":[]},{"resourceId":"6841FEE822F34D71BB262E1BC1212863","resurl":"/admin/appTheme","flag":"1","isParent":0,"icon":"aa","description":"Thematic management","sort":28,"resname":"Thematic management","type":"1","parentId":"F901703D395D4BDEBC739BB56D48EE5B","rescode":"appTheme-list","cdate":{"date":28,"hours":11,"seconds":3,"month":7,"timezoneOffset":-480,"year":118,"minutes":49,"time":1535428143000,"day":2},"mdate":{"date":28,"hours":11,"seconds":3,"month":7,"timezoneOffset":-480,"year":118,"minutes":49,"time":1535428143000,"day":2},"sysResources":[]},{"resourceId":"F2EC9391B0194BC68D76756C14CE3ACD","resurl":"/admin/appReport","flag":"1","isParent":0,"icon":"aa","description":"Reporting management","sort":28,"resname":"Reporting management","type":"1","parentId":"F901703D395D4BDEBC739BB56D48EE5B","rescode":"appReport-list","cdate":null,"mdate":{"date":30,"hours":11,"seconds":31,"month":7,"timezoneOffset":-480,"year":118,"minutes":41,"time":1535600491000,"day":4},"sysResources":[]},{"resourceId":"FAB41C77A348464695C8B34778068F8B","resurl":"/admin/sysReview","flag":"1","isParent":0,"icon":"review","description":"Comment management","sort":12,"resname":"Comment management","type":"1","parentId":"F901703D395D4BDEBC739BB56D48EE5B","rescode":"sysReview-list","cdate":{"date":27,"hours":10,"seconds":19,"month":7,"timezoneOffset":-480,"year":118,"minutes":47,"time":1535338039000,"day":1},"mdate":{"date":27,"hours":10,"seconds":19,"month":7,"timezoneOffset":-480,"year":118,"minutes":47,"time":1535338039000,"day":1},"sysResources":[]}]}],"status":200}

What do you mean? The original double quotation mark has been converted into the tag of & quote; by default, that is to say, the double quotation mark has been explained in html. I don't know the principle here. The solution is to solve it, but I feel that it's not a cure for the symptoms, so I'll record the problem and leave a message for you. Thank you.
A temporary solution is to replace & quote; with double quotes by using JS string replacement.

//This resData is the json string passed from the background. It is used here because JS has no replaceAll method,
So I added a / g to represent the global match, that is, on behalf of replaceAll, the students who want to know how to query by themselves
resData=resData.replace(/"/g,"\"");
//In addition, because the above is a json string, it can't use its properties and methods like an object, and it needs to
 Using JS built-in parsing method to convert json string into json object
resData=JSON.parse(resData);

Finally, the problem is solved successfully, and the data binding is successful.

Posted by SnakeO on Mon, 30 Dec 2019 06:44:52 -0800