Converting java JSONObject to javascript -


i have jsonobject i'm sending through ajax.

jsonobject obj = new jsonobject(); obj.put("nblike", result); obj.put("username", "bill"); 

then in success function want access obj properties. eg : username

i'have tried json.parse(obj) got error : uncaught syntaxerror: unexpected token '

server side log shows : {"username":"bill","nblike":1} //log.info(obj)

client side log show : ['username':'bill', 'nblike':1] //console.log(result)

i'd :

console.log("username : " + obj.username) 

thank you

convert jsonobject string before sending frontend , add "application/json" content-type of response. can use simple js object, don't need convert it.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -