I have been using JSON.parse() function to deserialize JSON object, It is not working for special characters. For example, if the JSON contains a date it being converted as 2012/04/18 instead of 2012/04/18. As per the info in this site https://success.salesforce.com/issues_view?id=a1p30000000wkAIAAY there is a function $A.util.json.encode() to serialize. I'm searching for function to deserialize a JSON in controllerJS.

Search :  function(component, event, helper) {
    var searchtext  = component.find("searchtext").get("v.value");
    var model       = component.find("Model").get("v.value");
    var brand       = component.get("v.Brand");
    var subcategory = component.get("v.SubCategory");
    var category    = component.get("v.Category");
    var page    = component.get("v.pageIndex");
    var Size    = component.get("v.pageSize");

    var action = component.get("c.KnowledgeDocs");
    action.setParams({"brand" : brand,
                      "model" : model,
                      "category" : category,
                      "subcategory" : subcategory,
                      "searchText" : searchtext,
                      "pageNumber" : page,
                      "pageSize" : Size});
        var responses = result.getReturnValue();
        if(component.isValid() && result.getState() === "SUCCESS"){
            var response = JSON.parse( responses );
            console.log($A.util.json.encode( response ));

Apex Class

public static string KnowledgeDocs(string brand, string model, string category, string subcategory, string searchText, integer pageNumber, integer pageSize){
    CCService.PublicationSearchRequest searchParams = new CCService.PublicationSearchRequest();

            new CCService.Attributes(CCService.FILTER_CRITERIA_BRAND, brand, eqCondition.name()));
            new CCService.Attributes(CCService.FILTER_CRITERIA_MODEL, model, eqCondition.name()));
            new CCService.Attributes(CCService.FILTER_CRITERIA_CATEGORY, category, eqCondition.name()));
            new CCService.Attributes(CCService.FILTER_CRITERIA_SUBCATEGORY, subcategory, eqCondition.name()));

        new CCService.Attributes(CCService.FILTER_CRITERIA_SEARCH, null, containsCondition.name(), searchText, 'OR'));

   /*dosearch makes an rest call and returns body from the response*/

    CCService.PublicationSearchContent publications = CCService.doSearch(searchParams);
    return Json.serialize(publications);
  • What does your Apex controller look like? What does KnowledgeDocs() return?
    – Folkert
    Feb 17 '17 at 12:14
  • @Folkert KnowledgeDocs() returns a JSON string.
    – Venky
    Feb 17 '17 at 12:58
  • Can you post the code for the controller as well? Does it serialize the JSON based on an Apex Class or did you build it yourself using string concatenation?
    – Folkert
    Feb 17 '17 at 12:59

You can take a look on System.JSON class that has various methods for serializing and deserializing. (salesforce also has other kinds of json support). You might need a round trip to server though.

  • thanks for quick response, but do they work in ControllerJS of the lightning component as in Apex Class. Please take a look at my code just updated my post.
    – Venky
    Feb 17 '17 at 12:01

By using this component I'm getting the required output.

<aura:unescapedHtml value=""/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.