Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
i am getting the rest api response like below
Response Body: {"id":"dsajnddna","id2":"orn","id3":"orndawdw"}
now i want get the id2 value from this body, i am unable to get the id2 value. please help mee
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
If your response body is a JSON string:
var responseBody = '{"id":"dsajnddna","id2":"orn","id3":"orndawdw"}';
var obj = JSON.parse(responseBody);
var id2 = obj.id2; // "orn"
If your response body is already a JSON object:
var id2 = responseBody.id2;
If you need to guard against missing fields:
var id2 = (obj && obj.id2) ? obj.id2 : null;
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
If your response body is a JSON string:
var responseBody = '{"id":"dsajnddna","id2":"orn","id3":"orndawdw"}';
var obj = JSON.parse(responseBody);
var id2 = obj.id2; // "orn"
If your response body is already a JSON object:
var id2 = responseBody.id2;
If you need to guard against missing fields:
var id2 = (obj && obj.id2) ? obj.id2 : null;