You need to sign in to do that
Don't have an account?
Rajan
Getting error in VF page while parsing JSON
Hi Friends,
My JSOn is - {"InvalidData"{"userType":null,"status":"success","sessionToken":null,"name":null,"message":"success","mappingId":null,"emailId":null,"data":null,"code":1000}}
But VF is returning - {"InvalidData":{"userType":null,"status":"success","sessionToken":null,"name":null,"message":"success","mappingId":null,"emailId":null,"data":null,"code":1000}}
So how to remove this " so that I can get the correct JSON as per my class.
My method is as below:
****************************
@RemoteAction
global static String inValid(integer dataId,boolean contactValid, boolean productValid,
boolean actionValid,String other){
integer contact = 0;
integer action = 0;
integer product = 0;
if(contactValid == true){
contact = 1;
}
if(productValid == true){
product = 1;
}
if(actionValid == true){
action = 1;
}
SalesAIRecommendations.Item response = new SalesAIRecommendations.Item();
Recommendation__c recommendation = [SELECT Id,Recom_External_Id__c,Feedback__c FROM Recommendation__c where Recom_External_Id__c =: dataId];
if(recommendation != null){
system.debug('valid recommendation Id');
recommendation.Feedback__c = other;
update recommendation;
Invalid_Recommendation__c invRec = new Invalid_Recommendation__c();
invRec.Recommendation_ID__c = recommendation.Recom_External_Id__c;
invRec.productChange__c = product;
invRec.Next_Best_Action__c = action;
invRec.contactId__c = contact;
invRec.Others__c = recommendation.Feedback__c;
insert invRec;
response.status='success';
response.code=1000;
response.message = 'success';
system.debug('{"InvalidData":' + JSON.serialize(response) + '}');
return '{"InvalidData":' + JSON.serialize(response) + '}';
}
else{
system.debug('invalid recommendation Id');
response.status='failure';
response.code=1001;
response.message = 'failure';
system.debug('******:' + '{"InvalidData":' + JSON.serialize(response) + '}');
return '{"InvalidData":' + JSON.serialize(response) + '}';
}
}
My JSOn is - {"InvalidData"{"userType":null,"status":"success","sessionToken":null,"name":null,"message":"success","mappingId":null,"emailId":null,"data":null,"code":1000}}
But VF is returning - {"InvalidData":{"userType":null,"status":"success","sessionToken":null,"name":null,"message":"success","mappingId":null,"emailId":null,"data":null,"code":1000}}
So how to remove this " so that I can get the correct JSON as per my class.
My method is as below:
****************************
@RemoteAction
global static String inValid(integer dataId,boolean contactValid, boolean productValid,
boolean actionValid,String other){
integer contact = 0;
integer action = 0;
integer product = 0;
if(contactValid == true){
contact = 1;
}
if(productValid == true){
product = 1;
}
if(actionValid == true){
action = 1;
}
SalesAIRecommendations.Item response = new SalesAIRecommendations.Item();
Recommendation__c recommendation = [SELECT Id,Recom_External_Id__c,Feedback__c FROM Recommendation__c where Recom_External_Id__c =: dataId];
if(recommendation != null){
system.debug('valid recommendation Id');
recommendation.Feedback__c = other;
update recommendation;
Invalid_Recommendation__c invRec = new Invalid_Recommendation__c();
invRec.Recommendation_ID__c = recommendation.Recom_External_Id__c;
invRec.productChange__c = product;
invRec.Next_Best_Action__c = action;
invRec.contactId__c = contact;
invRec.Others__c = recommendation.Feedback__c;
insert invRec;
response.status='success';
response.code=1000;
response.message = 'success';
system.debug('{"InvalidData":' + JSON.serialize(response) + '}');
return '{"InvalidData":' + JSON.serialize(response) + '}';
}
else{
system.debug('invalid recommendation Id');
response.status='failure';
response.code=1001;
response.message = 'failure';
system.debug('******:' + '{"InvalidData":' + JSON.serialize(response) + '}');
return '{"InvalidData":' + JSON.serialize(response) + '}';
}
}
Your VF remoting code in VF will be smilar(Syntax wise) to above code.
If you make {escape: false} then, auto html encoding will be disabled and VF will return correct JSON.
All Answers
Your VF remoting code in VF will be smilar(Syntax wise) to above code.
If you make {escape: false} then, auto html encoding will be disabled and VF will return correct JSON.
Try to replace the " with "
For example :
The JSON = [ { "id": 123, "text": "Consumer", "parent": "#" } ]
Then, use JSON.replace(/"/g,'"'));
system.debug('Result :' + JSON);
You can notice that all the " are replaced.
Thanks,
Sravan
You have solved this issue. It was coming because escape was true so I changed it to false as {escape: false}.
Thanks alot for resolving this issue because I was trying from last 1 day.
Can you please help for one requirement.
I have to design a custom button for converting records in opportunity.
I have a table in which I am displaying data from Account, contact and 3 custom objects like attached pic. Whenever I'll select any record from this table using checkbox and click on that button then it should create opportunity. Any suggestion or sample code will be helpful.
https://pritamshekhawat.wordpress.com/tag/wrapper-class/
Check above link, you may get some idea.
I am using the {escape: false} but now i am getting the below json in VF remote.
newCustomer={\"salutation\":\"Mr\",\"firstName\":\"Arpit\",\"lastName\":\"Test\",\"primaryPhone\":\"1234\",\"department\":\"Management\",\"companyName\":\"test\",\"vatNumber\":\"1234\",\"language\":\"en_US\",\"currencyCode\":\"EUR\",\"billingAddress\":{\"address1\":\"test\",\"postalCode\":\"1234\",\"city\":\"test\",\"stateCode\":\"AL\",\"countryCode\":\"US\"},\"username\":\"ARBAJPAI\",\"termsAndConditionFlag\":\"on\",\" \":\"\",\"state\":\"AL\",\"country\":\"US\",\"terms\":true,\"newsLetter\":false,\"companyType\":\"ISP\"}}
any help is appreciated how to resolve this issue