Reputation: 35
I am getting the following error. I have looked through the forums and I can't seem to find any help. The main problem is that I can't replicate it, I have tried on different browsers etc and I can't replicate it.
I am only getting it on a few client machines.
[ArgumentException: Invalid JSON primitive: .]
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() +930307
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) +376
System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) +120
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) +57
Telerik.Web.UI.RadButton.LoadPostData(String postDataKey, NameValueCollection postCollection) +238
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +1018
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2653
Can you give any suggestions on where I can look to find the error.
I want to clarify that I cannot replicate this issue, it seems to be happening on a few client machines , but I cant work out what the source of the error could be.
Upvotes: 3
Views: 7238
Reputation: 31337
The problem may not be a period (.) in the JSON response. Review the actual JSON response string and see if it contains any extraneous characters. For me there was an unexpected method name surrounding the JSON object.
string json = "WeirdMethodName({...});"
I just needed to remove the extraneous method name.
var json = client.DownloadString(apiUrl);
json = json.Replace("WeirdMethodName(", "").Replace(");","");
var serializer = new JavaScriptSerializer();
var someModel = serializer.Deserialize<SomeModel>(json);
Upvotes: 2
Reputation: 7591
looks like you have a value somewhere that is just a period. not a string, int, date or object. This could be causing the problem. Find out where the "." is coming from and you should be able to solve the serialization problem.
Upvotes: 0