如何避免System.ArgumentException:无效的JSON原语:new。在c#中解析json时

时间:2012-03-08 17:31:20

标签: c# asp.net json

我正在使用microsoft json解析器解析json:

        var json = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue };
        return json.DeserializeObject(jsonStr);

当我从服务器上关注json时:

[{"date_of_birth": new Date("Thu, 17 Nov 1983 00:01:00 GMT")},{"date_of_birth": new Date("Wed, 23 Nov 1904 00:01:01 GMT")}]

它会引发异常:

System.ArgumentException: Invalid JSON primitive: new.
   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)
   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeList(Int32 depth)
   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
   at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
   at System.Web.Script.Serialization.JavaScriptSerializer.DeserializeObject(String input)

如何摆脱这种情况?

0 个答案:

没有答案