2016-12-29 46 views
0

如果json對象不包含引號,則一切正常。幫助請 例外:ServiceStack無法將json對象與字符串中的引號反序列化爲字典<string,string>

{"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}} 
+0

不包含引號的JSON不是有效的JSON。請更新您的答案,以顯示完整的異常StackTrace和您用於反序列化的代碼。 – mythz

回答

1

如果JSON對象不包含引號,那麼它被視爲JSV。 ServiceStack的默認格式是JSV而不是JSON。

使用

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

解析JSON字符串到所需的類型。

相關問題