ServiceStack不能将带有引号的json对象反序列化为字典<string,string =“”>

时间:2016-12-29 10:44:25

标签: c# json serialization servicestack

如果json对象不包含引号,那么一切都没问题。请帮忙 例外:

{"ResponseStatus":{"ErrorCode":"SerializationException","Message":"Unable to bind to request 'CompanyList'","StackTrace":"   в ServiceStack.Serialization.StringMapTypeDeserializer.PopulateFromMap(Object instance, IDictionary`2 keyValuePairs, List`1 ignoredWarningsOnPropertyNames)\r\n   в ServiceStack.Host.RestPath.CreateRequest(String pathInfo, Dictionary`2 queryStringAndFormData, Object fromInstance)\r\n   в ServiceStack.Host.RestHandler.CreateRequest(IRequest httpReq, IRestPath restPath, Dictionary`2 requestParams, Object requestDto)\r\n   в ServiceStack.Host.RestHandler.CreateRequest(IRequest httpReq, IRestPath restPath)\r\n   в ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)","Errors":[{"ErrorCode":"SerializationException","FieldName":"query","Message":"'{\"Unknown\":\"company \\\"Railways\\\"\"}' is an Invalid value for 'query'"}],"Meta":null}}

1 个答案:

答案 0 :(得分:1)

如果json对象不包含引号,则将其视为JSV。 ServiceStack的默认格式是JSV而不是JSON。

使用

T JsonSerializer.DeserializeFromString<T>(string value);

将json字符串解析为所需类型。