0

I use amazonaws library[com.amazonaws.util.json] (java) for generate json . I use something as follows

    private static final String boldHtmlOpenTag = "<b>";
private static final String boldHtmlCloseTag = "</b>";
private static final String italicsHtmlOpenTag = "<i>";
private static final String italicsHtmlCloseTag = "</i>";
    String result = boldHtmlOpenTag + "hello" + boldHtmlCloseTag;
    jsonobj.put("test",result);

I get the response as {"test" : <b> hello<\/b>}. I need output as without the \. Thanks in advance.

6
  • I want to include html tags in json, But at the closing tags I got an escape slash may be added by the json library. Commented Jul 18, 2012 at 13:42
  • I'm asking about the code you posted on the question, because it isn't java right? Commented Jul 18, 2012 at 13:43
  • @Francisco Spaeth I use java code and amazonaws eclipse toolkit Commented Jul 18, 2012 at 13:45
  • I asked because it isn't a valid Java code, string isn't a known type, and if you don't add the ; at the end of the line you will not finish the sentence. Commented Jul 18, 2012 at 13:50
  • @Francisco Spaeth its only sample Commented Jul 18, 2012 at 13:51

3 Answers 3

1

If I'm understanding you correctly, why not just do

result = result.replace("\\","");

EDIT: Okay, then why not do this:

boldHtmlCloseTag = "<&frasl;b>";

That should still be legal JSON.

Sign up to request clarification or add additional context in comments.

1 Comment

The problem is my genaerated json value is a string with htmltags inside it.At the closing part the amazon lib put an extra backslash
0

The problem doesn't seems there. I suppose the value containing the tags you load from somewhere else, and there the value is stored with this escape char.

I conclude this because:

  1. the sample given is not java, what makes me feel that you just wrote a pseudo sample for this issue;
  2. the amazon json API doesn't comment anything about escape chars, and implementation is according API (I checked it).

So, please check from where you get the information and if there isn't stored with the wrong value.

3 Comments

I tried a small set of code in main function , I got the same result
import com.amazonaws.util.json.JSONException; import com.amazonaws.util.json.JSONObject; final String boldHtmlOpenTag = "<b>"; final String boldHtmlCloseTag = "</b>"; final String italicsHtmlOpenTag = "<i>"; final String italicsHtmlCloseTag = "</i>"; String str = boldHtmlOpenTag + italicsHtmlOpenTag + "Hello" + italicsHtmlOpenTag + boldHtmlCloseTag; String str1 ="<b>"+"hello"+"</b>"; JSONObject jsonobj = new JSONObject(); jsonobj.put("test", str1); System.out.println(jsonobj.toString());
Yea, i test it as a java applicaion
0

Try this one !

result = result.replace("\\\\","");

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.