我在使用Twitterizer的LookUp方法时遇到了JSON(反)序列化异常 . 例外情况说明:
反序列化对象时出现意外的标记:整数
这大致是我的代码:
// Populates the lookup options, requests the user details and processes the results
private void LookUpFollowersWithoutDetail(List<Follower> followersWithoutDetail)
{
LookupUsersOptions lookupOptions = new LookupUsersOptions();
for (int index = 0; index < followersWithoutDetail.Count && index < 100; index++)
{
lookupOptions.UserIds.Add(followersWithoutDetail[index].UserId);
}
RequestResult result = GetUserDetails(lookupOptions);
// process the results
}
获取用户详细信息的方法如下所示:
// Performs the lookup and saves the users to the database
private RequestResult GetUserDetails(LookupUsersOptions lookupOptions)
{
try
{
// Look up the followers
TwitterResponse<TwitterUserCollection> userLookupResponse =
TwitterUser.Lookup(_tokens, lookupOptions); // <-- Throws Exception
if (userLookupResponse.Result == RequestResult.Success)
{
SaveUserDetails(userLookupResponse);
}
return userLookupResponse.Result;
}
catch (Exception e)
{
Console.WriteLine("Exception in GetUserDetails: " + e.Message);
}
return RequestResult.Unknown;
}
我没有做任何花哨的事情,我只是在查找选项中放了一堆整数(跟随者的用户ID)然后我用这些选项调用查找方法 . 大多数情况下,该方法工作正常,但每隔一段时间我就会得到本文开头提到的异常 . 有没有人遇到类似Twitterizer的问题,他们是否找到了解决方案?
Update (for Ricky):
这是堆栈跟踪:
在Newtonsoft.Json.Serialization.Ivson.Serialization.JonSerializer.JonSerialPart上的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(对象newObject,JsonReader reader,JsonObjectContract Contract ,字符串id)中的Newtonsoft.Json.Serialization.JonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader,JsonObjectContract contract,String id) Newtonoft.Json的Newtonoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader,Type objectType,JsonContract contract,JsonProperty member,Object existingValue)的.JsonSerializerInternalReader.CreateObject(JsonReader reader,Type objectType,JsonContract contract,JsonProperty member,Object existingValue)在Newtonsoft的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty属性,JsonReader reader,Object target)中的.Serialization.JerialSerializerInternalReader.CreateValueProperty(JsonReader reader,JsonProperty属性,Object target,Boolean gottenCurrentValue,Object currentValue) . Newtonoft.Json.Serialization.JsonSerializerInternalReader.CreateObject中的Newtonoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader,JsonObjectContract contract,String id)中的Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject,JsonReader reader,JsonObjectContract contract,String id) (JsonReader reader,Type objectType,JsonContract contract,JsonProperty member,Object existingValue)Newtonsoft.Json.Serialization.JsonSerializerInternalReader中的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader,Type objectType,JsonContract contract,JsonProperty member,Object existingValue) . 在Newtonsoft.Json.Serializati的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty属性,JsonReader reader,Object target)中的.CreateValueProperty(JsonReader reader,JsonProperty属性,Object target,Boolean gottenCurrentValue,Object currentValue)在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader)的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader,JsonObjectContract contract,String id)上的on.JsonSerializerInternalReader.PopulateObject(Object newObject,JsonReader reader,JsonObjectContract contract,String id)在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty中的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader,Type objectType,JsonContract contract,JsonProperty member,Object existingValue)中的reader,Type objectType,JsonContract contract,JsonProperty成员,Object existingValue) (JsonReader reader,Type objectType,JsonContract Contract )在Newtonsoft.Json.Serialization.JsonSerializerInterna的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection wrappedList,JsonReader reader,String reference,JsonArrayContract contract)在Newtonsoft.Json.Utilities.CollectionUtils.CreateAndPopulateList(Type listType,Action2 populateList)的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader,String reference,JsonArrayContract contract)中的lReader . <> c_DisplayClass1.b_0(IList l,Boolean isTemporaryListReference) )在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader,Type objectType,JsonContract contract,JsonProperty成员,Object existingValue,String reference)中的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader,Type objectType,JsonContract contract, JintonProperty成员,Object existingValue)在Newtonsoft.Json.Serialization.JsonSerial.JsonSerial.Jon.Serialization.JsonSerializer内部调整函数的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader,Type objectType)中的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader,Type objectType,JsonContract Contract ) . Deseriali zenternal(JsonReader reader,Type objectType)at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader,Type objectType)at atNewtonsoft.Json.JsonConvert.DeserializeObject(String value,Type type,JsonSerializerSettings settings)Newtonsoft.Json.JsonConvert.DeserializeObject [T](String value,JsonSerializerSettings settings)Newtonsoft.Json.JsonConvert.DeserializeObject [T](String value)在Twitterizer.TwitterUser.Lookup(OAuthTokens)的Twitterizer.Core.TeritterAmand.TerformAction [T](ICommand1命令)上的Twitterizer.Core.TwitterCommand1.ExecuteCommand()上的Twitterizer.Core.SerializationHelper1.Deserialize(Byte [] webResponseData,DeserializationHandler deserializationHandler)令牌,LookupUsersOptions选项)位于C:\ Users \ user \ Path \ To \ MyClass.cs中的OBFUSCATED.System.OBFUSCATED.GetUserDetails(LookupUsersOptions lookupOptions):第306行
以下是发生此异常时提供的用户ID列表:
- lookupOptions.UserIds Count = 100 Twitterizer.TwitterIdCollection
[0] 39026441 decimal
[1] 360825202 decimal
[2] 377779483 decimal
[3] 77599652 decimal
[4] 199504556 decimal
[5] 15290529 decimal
[6] 15293368 decimal
[7] 15295132 decimal
[8] 15295838 decimal
[9] 15300610 decimal
[10] 15307479 decimal
[11] 15314695 decimal
[12] 15315646 decimal
[13] 15316087 decimal
[14] 15322893 decimal
[15] 15324552 decimal
[16] 15325815 decimal
[17] 15330982 decimal
[18] 15332031 decimal
[19] 15332318 decimal
[20] 15336542 decimal
[21] 15338843 decimal
[22] 15340130 decimal
[23] 15341396 decimal
[24] 15341681 decimal
[25] 15342905 decimal
[26] 15343278 decimal
[27] 15351598 decimal
[28] 15358123 decimal
[29] 15361196 decimal
[30] 15361723 decimal
[31] 15363684 decimal
[32] 15365834 decimal
[33] 15366588 decimal
[34] 15375866 decimal
[35] 15377256 decimal
[36] 15384679 decimal
[37] 15384994 decimal
[38] 15388036 decimal
[39] 15388874 decimal
[40] 15390556 decimal
[41] 15397486 decimal
[42] 15398320 decimal
[43] 15401318 decimal
[44] 15421131 decimal
[45] 15421937 decimal
[46] 15422192 decimal
[47] 15433173 decimal
[48] 15433807 decimal
[49] 15435566 decimal
[50] 15447574 decimal
[51] 15448831 decimal
[52] 15449755 decimal
[53] 15450751 decimal
[54] 15452924 decimal
[55] 15456465 decimal
[56] 15456590 decimal
[57] 15458653 decimal
[58] 15458901 decimal
[59] 15461998 decimal
[60] 15465107 decimal
[61] 15467755 decimal
[62] 15468099 decimal
[63] 15470126 decimal
[64] 15475251 decimal
[65] 15475461 decimal
[66] 15478303 decimal
[67] 15479254 decimal
[68] 15479572 decimal
[69] 15479736 decimal
[70] 15484821 decimal
[71] 15487227 decimal
[72] 15487287 decimal
[73] 15489577 decimal
[74] 15490132 decimal
[75] 15501961 decimal
[76] 15503943 decimal
[77] 15505543 decimal
[78] 15510316 decimal
[79] 15515724 decimal
[80] 15523378 decimal
[81] 15526558 decimal
[82] 15529204 decimal
[83] 15538443 decimal
[84] 15554417 decimal
[85] 15564955 decimal
[86] 15569189 decimal
[87] 15575242 decimal
[88] 15575635 decimal
[89] 15578111 decimal
[90] 15580710 decimal
[91] 15585660 decimal
[92] 15589332 decimal
[93] 15594166 decimal
[94] 15597341 decimal
[95] 15603662 decimal
[96] 15608792 decimal
[97] 15618128 decimal
[98] 15620785 decimal
[99] 15620915 decimal
+ Raw View
1 回答
在调查之后,我确定Twitter没有改变任何东西 . 这似乎是一个真正的实时错误,与解析地理位置数据有关 .
JSON.NET(Twitter用于反序列化json数据的库)将坐标值读取为long,但Twitterizer将其转换为double .
稍后两行代码并修复了错误 .
如果您想自己应用补丁,则修复程序位于Twitterizer2 \ Methods \ Geo \ Coordinate.cs中
第119行成为:
第123行变为: