1

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.

5
  • 5
    Json can't have comment, where did you get response like that? Commented Mar 12, 2014 at 15:38
  • I got the Response IBM Worklight server. Commented Mar 12, 2014 at 15:39
  • 5
    @xdazz: It's probably there to prevent people from stealing the JSON ;) Commented Mar 12, 2014 at 15:39
  • the same groups of people can or can't steal the JSON with or without the comments. So comments do nothing. Surely IBM would know this, awesome client-side devs that they are... Commented Mar 12, 2014 at 15:43
  • Yes. U r correct. but i want it to be json for my further process. Commented Mar 12, 2014 at 15:44

2 Answers 2

1

Should be a simple replace:

var resp = <string>;
resp = resp.replace(/^\/\*\-secure\-\n/, '').replace(/\*\/$/, '');
Sign up to request clarification or add additional context in comments.

2 Comments

in string how can i pass the whole string. "/*-secure-{"errors":["Runtime: Adapter 'DemoAdapter' does not exist"],"isSuccessful":false,"warnings":[],"info":[]}*/". each json object has double codes(").
Try escaping it: "here is a \"quote\"."
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.