简体   繁体   English

JsonConvert.DeserializeObject 在反序列化 CouchBase 响应时抛出异常

[英]JsonConvert.DeserializeObject throws exception when deserializing CouchBase response

I'm trying to deserialize JSON response from CouchBase.我正在尝试反序列化来自 CouchBase 的 JSON 响应。 However, deserialization throws an exception.但是,反序列化会引发异常。

            IQueryRequest queryRequest = QueryRequest.Create(queryString);
            queryRequest.ScanConsistency(ScanConsistency.RequestPlus);
            var queryResult = await bucket.QueryAsync<dynamic>(queryRequest);

            if (!queryResult.Success)
            {
            }

            foreach (var row in queryResult.Rows)
            {
                try
                {
                    var registrationDetails = JsonConvert.DeserializeObject<IEnumerable<RegistrationModel>>(row);
                    //var registrationDetail1 = JsonConvert.DeserializeObject<RegistrationModel>(row);
                }
                catch (Exception Ex)
                { }

            }

Exception I'm getting:我得到的例外:

{Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.IEnumerable<MC4B_CommonInterface.RegistrationModel>>(string)' has some invalid arguments
   at CallSite.Target(Closure , CallSite , Type , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at DataAccess.Services.RegistrationDataServices.ActivateSimpleRegistrations(ActivateRequest request) ...}

Response from Couchbase is straightforward. Couchbase 的回应很直接。 RegistrationModel has all the JsonProperty attributes. RegistrationModel具有所有JsonProperty属性。

[
  {
    "acsPntDocId": "",
    "adLis": "[]",
    "adP2DNa": "CA",
     .....
    }
]

One thing I've noticed, is the foreach (var row in queryResult.Rows) , row contains {{"acsPntDocId":"","adLis": "[]", ...}}我注意到的一件事是foreach (var row in queryResult.Rows)row包含{{"acsPntDocId":"","adLis": "[]", ...}}

Based on the string result you posted at the end of the question, it could be that row is already be a JObject.根据您在问题末尾发布的字符串结果,该row可能已经是 JObject。 Based on this post https://stackoverflow.com/a/44308752/579148 it seems that adding .ToString() to the jobject before deserializing it may do the trick for you.基于这篇文章https://stackoverflow.com/a/44308752/579148似乎在反序列化之前将.ToString()添加到 jobject 可能对你有用。

For example:例如:

string rowString = row.ToString();
var registrationDetails = JsonConvert.DeserializeObject<IEnumerable<RegistrationModel>>(rowString);

暂无
暂无

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

相关问题 将具有十六进制值的JSON反序列化为sbyte属性时,JsonConvert.DeserializeObject引发异常 - JsonConvert.DeserializeObject throws an exception when deserializing JSON with a hex value into an sbyte property 反序列化为数据集时,JsonConvert.DeserializeObject 不起作用 - JsonConvert.DeserializeObject is not working when deserializing to a DataSet JsonConvert.DeserializeObject()抛出StackOverflow异常 - JsonConvert.DeserializeObject() throws StackOverflow exception JsonConvert.DeserializeObject <DataTable> 引发异常 - JsonConvert.DeserializeObject<DataTable> throws an exception 在JsonConvert.DeserializeObject中反序列化对象时出现意外的标记 - Unexpected token when deserializing object in JsonConvert.DeserializeObject 尝试将byte []反序列化为IEnumerable时,JsonConvert.DeserializeObject引发异常<byte> - JsonConvert.DeserializeObject throws an exception when attempting to deserialize byte[] to IEnumerable<byte> 反序列化字符串时出现 JsonConvert.DeserializeObject 错误 - JsonConvert.DeserializeObject error while deserializing a string JsonConvert.SerializeObject 后跟 JsonConvert.DeserializeObject 抛出 InvalidCastException - JsonConvert.SerializeObject followed by JsonConvert.DeserializeObject throws InvalidCastException 使用 JsonConvert.DeserializeObject (Newtonsoft.Json) 反序列化时丢失不可打印的 ascii 字符(组分隔符) - Losing non printable ascii character (group separator) when deserializing with JsonConvert.DeserializeObject (Newtonsoft.Json) JsonConvert.DeserializeObject问题 - JsonConvert.DeserializeObject issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM