简体   繁体   English

Twitterizer引发异常:反序列化对象时发生意外的令牌:整数

[英]Twitterizer throwing an exception: Unexpected token when deserializing object: Integer

I'm encountering a JSON (de)serialization exception when using Twitterizer 's LookUp method. 使用TwitterizerLookUp方法时,我遇到JSON(反序列化)异常。 The exception states: 异常指出:

Unexpected token when deserializing object: Integer 反序列化对象时出现意外令牌:整数

Here is roughly what my code looks like: 我的代码大致如下所示:

// 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
}

The method that gets the user details looks like this: 获取用户详细信息的方法如下所示:

// 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;
}

I don't do anything fancy, I just put a bunch of integers (User Id's of the followers) in the lookup options and then I call the lookup method with those options. 我没有做任何花哨的事情,我只是在查询选项中放了一堆整数(跟随者的用户ID),然后使用这些选项调用查询方法。 Most of the time the method works fine, but every once in a while I get the exception mentioned in the beginning of this post. 在大多数情况下,该方法都能正常工作,但偶尔我会收到本文开头提到的异常。 Has anybody encountered a similar issue with Twitterizer and have they figured out a solution? 有人在Twitterizer上遇到过类似的问题吗,他们找到了解决方案吗?

Update (for Ricky): 更新(针对Ricky):

Here is the stack trace: 这是堆栈跟踪:

at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueProperty(JsonReader reader, JsonProperty property, Object target, Boolean gottenCurrentValue, Object currentValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonReader reader, Object target) at Newtonsoft.Js 在Newton的Newton.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader的读者,JsonObjectContractS。合同,字符串id。)在Newton的Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject,JsonReader reader,JsonObjectContract contract,String id)。 JsonSerializerInternalReader.CreateObject(JsonReader reader,Type objectType,JsonContract contract,JsonProperty member,Object existValue)在Newton.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader,Type objectType,JsonContract contract,JsonProperty成员Newton。在Newton的序列化。 on.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueProperty(JsonReader reader, JsonProperty property, Object target, Boolean gottenCurrentValue, Object currentValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonReader reader, Object target) at Newtonsoft.Json.Serialization Newton.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader读者,JsonObjectContracter合同,字符串id)在Newtonsoft.JsonSizer。 (Newsonsoft.Json.Serialization.Internal(JsonReader reader,Type objectType,JsonContract contract,JsonProperty member,Object existValue)在Newton.Json.Serialization.JsonSerializer。 Newton.Json.Serialization的.CreateValueProperty(JsonReader阅读器,JsonProperty属性,对象目标,布尔型gettenCurrentValue,Object currentValue)在Newton.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty属性,JsonReader阅读器,对象目标) .JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection wrappedList, JsonReader reader, String reference, JsonArrayContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalR Newton.JsonSerializer.JsonSerializer(JsonSerializer.Object.Create.JsonSerializerInternalReader.PopulateObject(Object newObject,JsonReader reader,JsonObjectContract contract,String id)在牛顿软件公司。 ,位于Newton.Json.Serialization.JsonSertyizer(JsonSerializerIn(JsonSerializerIn( Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection包装的List,JsonReader阅读器,字符串引用,JsonArrayContract合同)的Newtonsoft.Json.Serialization.JsonSerializerInternalR的JsonReader阅读器,类型objectType,JsonContract合同) eader.<>c_ DisplayClass1.b _0(IList l, Boolean isTemporaryListReference) at Newtonsoft.Json.Utilities.CollectionUtils.CreateAndPopulateList(Type listType, Action 2 populateList) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader, String reference, JsonArrayContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String reference) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(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 Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at Twitterizer.Core.SerializationHelper eader。<> c_ DisplayClass1.b _0(IList l,布尔值isTemporaryListReference)在Newton.Json.Utilities.CollectionUtils.CreateAndPopulateList(Type listType,Action 2 populateList) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader, String reference, JsonArrayContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String reference) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(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 Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at Twitterizer.Core.SerializationHelper 2 populateList) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader, String reference, JsonArrayContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String reference) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(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 Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at Twitterizer.Core.SerializationHelper 1.Deserialize(Byte[] webResponseData, DeserializationHandler deserializationHandler) at Twitterizer.Core.TwitterCommand 1.ExecuteCommand() at Twitterizer.Core.CommandPerformer.PerformAction[T](ICommand 1 command) at Twitterizer.TwitterUser.Lookup(OAuthTokens tokens, LookupUsersOptions options) at OBFUSCATED.System.OBFUSCATED.GetUserDetails(LookupUsersOptions lookupOptions) in C:\\Users\\user\\Path\\To\\MyClass.cs:line 306 2 populateList) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader, String reference, JsonArrayContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String reference) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(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 Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at Twitterizer.Core.SerializationHelper Twitterizer.Core.SerializationHelper 1.Deserialize(Byte [] webResponseData,DeserializationHandler deserializationHandler) 1.ExecuteCommand() at Twitterizer.Core.CommandPerformer.PerformAction[T](ICommand位于C:\\ Users \\中的OBFUSCATED.System.OBFUSCATED.GetUserDetails(LookupUsersOptions lookupOptions)的Twitterizer.TwitterUser.Lookup(OAuthTokens令牌,LookupUsersOptions选项)的Twitterizer.Core.CommandPerformer.PerformAction 1.ExecuteCommand() at Twitterizer.Core.CommandPerformer.PerformAction[T](ICommand 1命令)的1.ExecuteCommand() at Twitterizer.Core.CommandPerformer.PerformAction[T](ICommand user \\ Path \\ To \\ MyClass.cs:第306行

Here is the list of User Id's that were supplied when this exception occurred: 这是发生此异常时提供的用户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        

After looking into this, I've determined Twitter didn't change anything. 研究了这一点之后,我确定Twitter并没有进行任何更改。 This appears to be a real live bug having to do with parsing geo location data. 这似乎是一个实时漏洞,与解析地理位置数据有关。

JSON.NET (the library Twitterizer uses to deserialize json data) reads a coordinate value as a long, but Twitterizer is casting it as a double. JSON.NET(Twitterizer用于反序列化JSON数据的库)读取的坐标值很长,但Twitterizer将其转换为双精度值。

Two lines of code later and the bug is fixed. 两行代码之后,该错误已修复。

If you would like to apply the patch yourself, the fix is in Twitterizer2\\Methods\\Geo\\Coordinate.cs 如果您想自己应用补丁,则此修复程序位于Twitterizer2 \\ Methods \\ Geo \\ Coordinate.cs中。

Line 119 becomes: 第119行变成:

result[itemIndex].Latitude = Convert.ToDouble(reader.Value);

Line 123 becomes: 第123行变成:

result[itemIndex].Longitude = Convert.ToDouble(reader.Value);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Twitterizer2 1.2.4 Streaming API 异常 - 反序列化时意外结束 object - Twitterizer2 1.2.4 Streaming API exception - Unexpected end when deserializing object 填充对象异常反序列化抽象类时出现意外的初始标记'EndObject' - Unexpected initial token 'EndObject' when populating object exception deserializing abstract class 在JsonConvert.DeserializeObject中反序列化对象时出现意外的标记 - Unexpected token when deserializing object in JsonConvert.DeserializeObject 为什么反序列化到字典时JsonConvert会引发异常 - Why is JsonConvert throwing exception when deserializing to a dictionary Newtonsoft.Json.JsonSerializationException:'反序列化 object 时出现意外令牌:使用动态 Object 进行评论 - Newtonsoft.Json.JsonSerializationException: 'Unexpected token when deserializing object: Comment with Dynamic Object 反序列化json对象时的异常 - exception when deserializing json object 反序列化对象时读取 DataTable EndArray 时出现意外的 JSON 令牌 - Unexpected JSON token while reading DataTable EndArray While Deserializing Object C# JObject 反序列化多维数组时出现意外标记 - C# JObject Unexpected token when deserializing multidimensional array 使用Json.net反序列化时出现“意外的令牌:StartObject” - “Unexpected token: StartObject” when Deserializing with Json.net 反序列化为double时,JsonConvert会抛出一个“非有效整数”异常 - JsonConvert throws a 'not a valid integer' exception when deserializing to a double
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM