是否可以序列化" JsonValue"?

时间:2018-03-01 07:32:20

标签: c# json spring-rest

我尝试使用
来序列化JsonValue Spring.NET(v.1.2.0),Spring.NET REST Client 1.1.1,Newtonsoft.Json v.11.0.0。

我是这样做的

[DataContract]
public class ScanResponse : BaseResponse
{
    [DataMember]
    public JsonValue Data { get; set; }
}

[ServiceContract]
public interface IHardwareWebService
{
    [OperationContract]
    [WebInvoke(UriTemplate = "/scan/",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json,
        Method = "*")]
    ScanResponse Scan();
}

public ScanResponse Scan()
{ 
    ScanResponse response = new ScanResponse();
    try
    {
        if (AddedCorsHeaders()) 
            return response; 
        response = _WebServiceLogic.Scan(ScanParams); 
        return response;
    } 
    catch (Exception ex) 
    {
        SystemLog.Logger.Error("Scan error", ex); 
        response.Error = new Assets.Error("Scan error: " + ex.Message); 
        return response;
    }
}

public ScanResponse Scan(HardwareService.Assets.ScanParameters scanParams)
{
    ScanResponse resultData = new ScanResponse();
    /*
    .....
    */
    resultData.Data = JsonValue.Parse(Scanner.GetData());
    return resultData;
}

数据未被序列化(没有错误或例外)。

如果更改为:

[DataMember]
public string Data { get; set; }

public ScanResponse Scan(HardwareService.Assets.ScanParameters scanParams)
{
    ScanResponse resultData = new ScanResponse();
    /*
    .....
    */
    resultData.Data = Scanner.GetData();
    return resultData;
}

数据序列化,可能是什么原因。 我将非常感谢你的帮助!

0 个答案:

没有答案