问题
Example is the following, where T is some DTO that I expect to get 1...n back matching the resultCount. This loaded up fine using Jayrock JsonConvert, however is just returning a new JsonResult to me when trying to deserialize the same json text that worked in Jayrock.
[Serializable]
public class JsonResult<T>
{
public int resultCount = 0;
public T[] results;
}
I thought this might be an issue that I asked about at ServiceStack.Text.JsonSerializer.DeserializeFromString<T>() fails to deserialize if string contains \n's, however even stripping out those \n's still doesn't allow deserialization to succeed.
回答1:
ServiceStack's JSON Serializer does support generics but only serializes public properties which is the problem here.
Also the [Serializable]
attribute has no significance in most (all?) serailizers outside of .NET, including all of ServiceStack's serializers.
来源:https://stackoverflow.com/questions/12771101/can-servicestack-text-deserialize-json-to-a-custom-generic-type