Uncaught SyntaxError: Unexpected token in JSON at position 30 with escaped unicode character

 

When you execute the JavaScript code:

JSON.parse(“\”This is a unicode character: \u0007\””)

in a browser you will get the error:

Uncaught SyntaxError: Unexpected token in JSON at position 30
     at JSON.parse (<anonymous>)
     at <anonymous>:1:6

I fixed this by altering the C# code that returned the JSON.


public
static
class
MvcHelper

{


public
static
ActionResult ConvertToJsonActionResult(object data)

{


var content = ConvertToCamelCaseJsonString(data);

content = RemoveEscapedUnicodeCharactersFromString(content);


return ConvertStringToJsonContentResult(content);

}

 


private
static
string ConvertToCamelCaseJsonString(object data)

{


var serializationSettings =


new
JsonSerializerSettings

{

ContractResolver = new
CamelCasePropertyNamesContractResolver()

};


return
JsonConvert.SerializeObject(data, serializationSettings);

}

 


private
static
ContentResult ConvertStringToJsonContentResult(string content)

{


return


new
ContentResult()

{

Content = content,

ContentType = “application/json”,

ContentEncoding = System.Text.Encoding.UTF8

};

}

 


private
static
string RemoveEscapedUnicodeCharactersFromString(string content)

{


var regex = new System.Text.RegularExpressions.Regex(@”\\+[uU]([0-9A-Fa-f]{4})”);


return regex.Replace(content, string.Empty);

}

}

 

Then you can convert your C# ViewModel to a Json ActionResult:

[HttpPost]


public
ActionResult WizardData(int taakId)

{


var model = new
MyViewModelViewModel();

 


return
MvcHelper.ConvertToJsonActionResult(model);

}

 

 

 

 

 

 

 

 

Microsoft Word 2016: Word cannot register your account. The provider where you are trying to publish is unavailable. Contact your provider for assistance.

 

I was getting the error: “Word cannot register your account. The provider where you are trying to publish is unavailable. Contact your provider for assistance.”

This was caused by me forgetting to add ” /xmlrpc.php” to the end of the url.

So if you want to register a blog “https://my.blog.com” in Word 2016, then you should use the url “https://my.blog.com/xmlrpc.php ”