manjakannar
manjakannar

Reputation: 61

How to remove string from the json response

I'm receiving a response like this:

/*-secure-{"errors":["Runtime: Adapter 'DemoAdapter' does not exist"],"isSuccessful":false,"warnings":[],"info":[]}*/

But I only want the JSON data from the response. Like this:

{
 "errors":       ["Runtime: Adapter 'DemoAdapter' does not exist"],
 "isSuccessful": false,
 "warnings":     [],
 "info":         []
}

How do I remove the /*-secure- from the start and */ from the end of the response.

Upvotes: 1

Views: 1533

Answers (2)

manjakannar
manjakannar

Reputation: 61

I got the answer:

var str = '/*-secure-{"errors":["Runtime: Adapter "DemoAdapte" does not exist"],"isSuccessful":false,"warnings":[],"info":[]}*/';
var res = str.substring(10,str .length-2);

syntax is like this.

var str = data;
var res = str.substring(10,str .length-2);

where data is whatever string u get the response.

Upvotes: 1

beautifulcoder
beautifulcoder

Reputation: 11320

Should be a simple replace:

var resp = <string>;
resp = resp.replace(/^\/\*\-secure\-\n/, '').replace(/\*\/$/, '');

Upvotes: 1

Related Questions