Save Return Error in Sitecore Page Editor
Asked Answered
J

3

5

I get an error when save a page in page editor.. Somehow when I edited the page from presentation > detail and display it in page editor it works fine.. The error logs is in below here..

ERROR After parsing a value an unexpected character was encountered: {. Path 'scLayout', line 38, position 85.  Exception: Newtonsoft.Json.JsonReaderException
Message: After parsing a value an unexpected character was encountered: {. Path 'scLayout', line 38, position 85.  Source: Newtonsoft.Json 
    at Newtonsoft.Json.JsonTextReader.ParsePostValue()
    at Newtonsoft.Json.JsonTextReader.ReadInternal()
    at Newtonsoft.Json.JsonTextReader.Read()
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
    at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
    at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
    at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
    at Sitecore.ExperienceEditor.Speak.Server.Requests.PipelineProcessorRequest`1.Process(RequestArgs requestArgs)

Any kind of thought or solution may help

Thanks

Jijib answered 27/1, 2016 at 5:45 Comment(2)
are you using coveo on your project ? if yes please check this link: developers.coveo.com/display/public/SitecoreV3/…Biphenyl
No, I don't use Coveo and my sitecore is version 8.1.. And have different line error (line 38, position 85). Although, I already do the thing on that link and it's not workedJijib
T
7

This is being caused by a confirmed bug in Sitecore. (reference # 84051 when opening a ticket)

You can resolve this yourself, but I still recommend going through Sitecore so they can ensure that you have what you need.

To solve, look at the /sitecore/shell/client/Sitecore/ExperienceEditor/ExperienceEditor.js file, on line 510 you will see that decodeURIComponent is being called twice.

Updating it to only be called once like data: decodeURIComponent(JSON.stringify(commandContext)) will resolve the error.

Likewise, a change is required in the /sitecore/shell/client/Sitecore/ExperienceEditor/RibbonPageCode.js file on line 24.

Here, adding the decodeURIComponent method call is what fixes this file. So like this: ribbonUrl: decodeURIComponent(this.PageEditBar.get("url")),

This probably addresses the Coveo issue as well, but my clients are not currently using Coveo, so I can't verify that.

Tailorbird answered 16/2, 2016 at 21:20 Comment(7)
Lifesaver! This would have taken me ages to track down. Do you have a link to ticket #84051?Rupp
Sorry @DavidMasters, can't provide a link as it goes to the helpdesk. If you contact support with a new ticket and reference that number, they should be able to get you the correct fixes. Fixes just include updated js files. But suggested going through them in case there is anything else that might need to be tweaked in your individual solution.Tailorbird
OK, just wanted to know if the latest version fixes it. For the time being I've added the manually edited .js file into our VS solution. I'm just concious that if we upgrade sitecore at any point but keep publishing my out dated version of the file it could spell trouble.Rupp
It's not fixed as of 8.1 Update 1.Tailorbird
The Sitecore bug is fixed in Sitecore 8.1 Update-2.Whitley
Interesting enough, I have two installations of 8.1 update 1. One of the installations has this problem, and the other does not. I wonder if Sitecore sneakily patched this into later versions of 8.1.1?Ledaledah
Ran into this more than once, and here I am again at the solution. Thanks a ton!Ledaledah
S
2

This post fixed for me. Note I'm using Sitecore 8.2 Update 2

My error:

After parsing a value an unexpected character was encountered: {. Path 'scLayout', line 1, position 2246.

http://jockstothecore.com/experience-editor-error/

In the event that the above link does work, the instructions are to:

Edit the file, [Website]/sitecore/shell/client/Sitecore/ExperienceEditor/ExperienceEditor.js and to replace the code for postServerRequest function with this updated version.

postServerRequest: function (requestType, commandContext, handler, async) {
   
    function normalizeDeviceProp(d) {
        if (typeof(d) !== "object")
            throw new Error("Unexpected presentation details XML: cannot find device property");
     
        if (d instanceof Array)
            return d;
     
        var normalized = [];
        normalized.push(d);
        return normalized;
    }
       
    var token = $('input[name="__RequestVerificationToken"]').val();
 
    // Custom Brainjocks code to fix Experience Editor error.
    var ajaxData = unescape(JSON.stringify(commandContext));
    if (commandContext && commandContext.scLayout) {
        var obj = JSON.parse(commandContext.scLayout);
      if (obj && obj.r) {
          normalizeDeviceProp(obj.r.d).forEach(function (d) {
              if (d.r instanceof Array) {
                  d.r.forEach(function (r) {
                      var val = r["@par"];
                        if (val && val.length > 0) {
                            ajaxData = ajaxData.replace(unescape(val), val);
                        }
                  });
              }
                 
            });
        }
    }
 
    jQuery.ajax({
        url: "/-/speak/request/v1/expeditor/" + requestType,
        data: {
            __RequestVerificationToken: token,
            data: ajaxData
        },
        success: handler,
        type: "POST",
        async: async != undefined ? async : false
    });
}
Seiber answered 31/3, 2017 at 15:17 Comment(1)
this fixed for me in 8.2.3 the problem was, in rendering parameter if I add am image then the page cannot be saved(it gives error). and this fix fixed it!Henrik
S
0

Check the content of all of the fields being saved. The Experience/Page editor has to serialize everything into a json object to call its own internal API's. There might be a stray character in one of your fields tripping up the json serializer. I ran into this when the content editor had copy and pasted their content from elsewhere.

Salba answered 27/1, 2016 at 12:33 Comment(1)
I don't think so. because I know the field that give the error and I already check it whether it has stray character or not..Jijib

© 2022 - 2024 — McMap. All rights reserved.