使用JsonConvert.SerializeObject

时间:2015-06-11 02:43:43

标签: c# .net json.net tweetinvi

我试图让以下代码工作,但是当我尝试序列化对象时,会抛出一个未实现的异常。它声明"方法或操作未实现。"我已经尝试将ITweet作为一个具体的类实现,但我不能从接口到具体类。

private void SendToKinesis(ITweet tweet)
    {


        var dataAsJson = JsonConvert.SerializeObject(tweet);
        byte[] dataAsBytes = Encoding.UTF8.GetBytes(dataAsJson);

       //Send to Kinesis

    }

完全例外:

System.NotImplementedException:未实现方法或操作。    在Tweetinvi.Logic.JsonConverters.JsonPropertyConverterRepository.WriteJson(JsonWriter writer,Object value,JsonSerializer serializer)    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer,JsonConverter converter,Object value,JsonContract contract,JsonContainerContract collectionContract,JsonProperty containerProperty)    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer,Object value,JsonObjectContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer,Object value,JsonObjectContract contract,JsonProperty member,JsonContainerContract collectionContract,JsonProperty containerProperty)    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,Object value,JsonContract valueContract,JsonProperty member,JsonContainerContract containerContract,JsonProperty containerProperty)    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter,Object value,Type objectType)    at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter,Object value,Type objectType)    at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter,Object value,Type objectType)    在Newtonsoft.Json.JsonConvert.SerializeObjectInternalA类型的第一次机会异常' System.NotImplementedException'发生在TwitterIngestion.exe中 (对象值,类型类型,JsonSerializer jsonSerializer)    在Newtonsoft.Json.JsonConvert.SerializeObject(对象值,类型类型,JsonSerializerSettings设置)    at Newtonsoft.Json.JsonConvert.SerializeObject(Object value)    在TwitterIngestion.IngestionService.SendToKinesis(ITweet推文)c:\ Users \ sepehr500 \ Desktop \ Work Stuff \ TwitterIngestion \ TwitterIngestion \ IngestionTask.cs:第104行

1 个答案:

答案 0 :(得分:-1)

请尝试以下代码:

private void SendToKinesis(ITweet tweet)
{


    var dataAsJson = JsonConvert.SerializeObject<ITweet>(tweet);
    byte[] dataAsBytes = Encoding.UTF8.GetBytes(dataAsJson);

   //Send to Kinesis

}