You need to sign in to do that
Don't have an account?
JamesSS
How to find and replace single quote in string?
String s = 'This's is correct and it's ready to replace';
How to replace the single quote ?
replace character : '
Replacing with : '\
My expected output:
This\'s is correct and it\'s ready to replace
Is it possible?
How about using JSENCODE ?
$(document).ready(function() {
alert('{!JSENCODE(result)}');
});
All Answers
Try the String method escapeSingleQuotes
I have used escapeSingleQuotes. I am using json list to Page.That's why i got the error.Is any possible escapeSingleQuotes in Json List?
You were looking for a string method ? I guess escapeSingleQuotes does what u need
My output Json List:
[{"Name":"Test'","Phone":"9000000010"},{"Name":"Test'","Phone":"9000000010"}]
In above output, Name Contains Name+'(Test')
My code:
public String result{get;set;}
public Test() {
List<Account> AccountList = [SELECT Id,Name FROM Account];
result= Json.serialize(TopAccountsInnerList);
}
<apex:page controller="Test">
<apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"/>
<script type="text/javascript" charset="UTF-8">
$(document).ready(function() {
alert('{!result}');
});
</script>
</apex:page>
Avi How to escape characters in string for passing Json list in page?
How about using JSENCODE ?
$(document).ready(function() {
alert('{!JSENCODE(result)}');
});
Avi Its working.But it passing into parseJSON, its thorws unexpected string error.
My code:
var result = $.parseJSON('{!JSENCODE(result)}');
http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm
Thanks Avi