Jay Roy
asked on
json string error
hi guys
this is my json string
"TRADE_LAYOUT":{
"fields":{
"10021/INOPS-RAF +MONEY/INDIA":{
"id":"1160GB0421/UKOPS-FX INTERBANK PROC+INVEST/EMEA",
"order":7,
"caption":"10021
INOPS-RAF +MONEY
INDIA
",
"fields":"[object Object],[object Object]"
}
when i validate the json string in Json formatter ,it shows error in the
"caption". The error is >>Invalid characters found
Any idea how i can fix it?
thanks
this is my json string
"TRADE_LAYOUT":{
"fields":{
"10021/INOPS-RAF +MONEY/INDIA":{
"id":"1160GB0421/UKOPS-FX INTERBANK PROC+INVEST/EMEA",
"order":7,
"caption":"10021
INOPS-RAF +MONEY
INDIA
",
"fields":"[object Object],[object Object]"
}
when i validate the json string in Json formatter ,it shows error in the
"caption". The error is >>Invalid characters found
Any idea how i can fix it?
thanks
ASKER
but i am already doing '\n' on my java side and passing the json string to UI
like this
My java code
JSONObject myson = new JSONObject();
myson.put(CAPTION, returnFormatedName(name));
...
public String returnFormatedName(String name){
String code = "";
String aligner = " ";
StringTokenizer st = new StringTokenizer(name,"/");
StringBuffer codeText = new StringBuffer();
while (st.hasMoreTokens()) {
code = st.nextToken()+aligner;
codeText .append(code).append("\n");
}
return codeText .toString(); // caption would contain \n
}
and that is why i a am getting the caption in seperate line like this
"caption":"10021
INOPS-RAF +MONEY
INDIA
",
but when i validate my json it fails. any idea what i am missing?
thanks
like this
My java code
JSONObject myson = new JSONObject();
myson.put(CAPTION, returnFormatedName(name));
...
public String returnFormatedName(String name){
String code = "";
String aligner = " ";
StringTokenizer st = new StringTokenizer(name,"/");
StringBuffer codeText = new StringBuffer();
while (st.hasMoreTokens()) {
code = st.nextToken()+aligner;
codeText .append(code).append("\n");
}
return codeText .toString(); // caption would contain \n
}
and that is why i a am getting the caption in seperate line like this
"caption":"10021
INOPS-RAF +MONEY
INDIA
",
but when i validate my json it fails. any idea what i am missing?
thanks
In your java side, you should put \\n instead of \n.
ASKER
Ok will try that.. Can u plz tell me what is the difference between \\n and Single slash n
Thanks
Thanks
\n is an escaped newline.
\\n is an escaped of above one, escaped of escaped newline.
You need the escaped newline in your Java to print a new line, but you need the latter to print the escaped newline.
\\n is an escaped of above one, escaped of escaped newline.
You need the escaped newline in your Java to print a new line, but you need the latter to print the escaped newline.
ASKER
thanks
but when i use
while (st.hasMoreTokens()) {
code = st.nextToken();
codeText .append(code).append("\\n");
}
its displaying like this in the UI
10021\nINOPS-RAF +MONEY\nINDIA but i want the next line like this
10021
INOPS-RAF +MONEY
INDIA
but in the UI its not displaying in next line. It displays as
but when i use
while (st.hasMoreTokens()) {
code = st.nextToken();
codeText .append(code).append("\\n");
}
its displaying like this in the UI
10021\nINOPS-RAF +MONEY\nINDIA but i want the next line like this
10021
INOPS-RAF +MONEY
INDIA
but in the UI its not displaying in next line. It displays as
ASKER
any idea what i am doing wrong
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
actually i am using Flex on the UI ( sorry forgot to say that)
so <br> isnt working correctly, i am seeing
10021<br>INOPS-RAF +MONEY<br>INDIA
i know '\n' works fine with flex. any idea how i can make it work with flex
thanks
so <br> isnt working correctly, i am seeing
10021<br>INOPS-RAF +MONEY<br>INDIA
i know '\n' works fine with flex. any idea how i can make it work with flex
thanks
If use \\n, what does it look like?
ASKER
if i use \\n
it looks like
10021\nINOPS-RAF +MONEY\nINDIA
it looks like
10021\nINOPS-RAF +MONEY\nINDIA
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
any idea how i can make it work with 'text' only ?
I have the freedom to change the java code only..cant change the flex side
thanks
I have the freedom to change the java code only..cant change the flex side
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am actually using that json data to disply on a flex UI..so whats happening is the slashes are getting displayed as is.
What happened when you tried my suggestion?
Open in new window