相关疑难解决方法(0)

使用JObject和JProperty与JSON.Net 4.0

我试图以这种格式反序列化JSON:

{
   "data": [
      {
         "installed": 1,
         "user_likes": 1,
         "user_education_history": 1,
         "friends_education_history": 1,
         "bookmarked": 1
      }
   ]
}
Run Code Online (Sandbox Code Playgroud)

到这样一个简单的字符串数组:

{
    "installed",
    "user_likes",
    "user_education_history",
    "friends_education_history",
    "bookmarked"
}
Run Code Online (Sandbox Code Playgroud)

运用 JSON.NET 4.0

我已经使用`CustomCreationConverter'工作了

public class ListConverter : CustomCreationConverter<List<string>>
{
public override List<string> Create(Type objectType)
{
    return new List<string>();
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
    var lst = new List<string>();

    //don't care about the inital 'data' element
    reader.Read();

    while (reader.Read())
    {
        if (reader.TokenType == JsonToken.PropertyName)
        {
            lst.Add(reader.Value.ToString()); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net json json.net deserialization

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

asp.net ×1

c# ×1

deserialization ×1

json ×1

json.net ×1