-3

how to convert the following string to map so that i can access the values

data.message ="{"id":"60653","key":"project1","self":"http://127.0.0.1:321/rest/api/2/issue/project1"}"
Rajeev
  • 44,985
  • 76
  • 186
  • 285
  • 1
    change external double quotes to single quotes, or remove them, otherwise it's syntax error. – n-dru Jun 22 '15 at 13:27
  • Thats the JSONresponse including double quotes – Rajeev Jun 22 '15 at 13:28
  • If the source is indeed a string though, instead of you writing down a string, then JSON.parse() is what you are after. – GillesC Jun 22 '15 at 13:29
  • `var obj = JSON.parse(data.message);` will give you an object with properties you can access. – blex Jun 22 '15 at 13:30
  • Is that your actual code or are you just trying to represent the data you're getting? It's extremely confusing because it's invalid syntax so it's unclear if you're having problems with that or what the actual problem is. – JJJ Jun 22 '15 at 13:31

2 Answers2

1

if your string is a valid JSON just use the JSON.parse function:

var str = '{"id":"60653","key":"project1","self":"http://127.0.0.1:321/rest/api/2/issue/project1"}'
var mydata = JSON.parse(str);
n00dl3
  • 21,213
  • 7
  • 66
  • 76
0

Use JSON.parse

Here's the corresponding MDN documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

dmcqu314
  • 875
  • 11
  • 29