我将我的json作为值传递给
var checkthis = JsonConvert.DeserializeObject(value);
string dothis = checkthis.ToString();
Activity activity = new CompressedJsonActivityTransformer().Deserialize(dothis);
我需要关注我内置的CompressedJsonActivityTransformer,但我一直在活动活动中获得System.NullReferenceException
。
我需要通过这个自定义反序列化器实现
public class CompressedJsonActivityTransformer:IActivitySerializer,IActivityDeserializer
{
public CompressedJsonActivityTransformer();
public Activity Deserialize(Stream stream);
public Activity Deserialize(string jsonData);
public void Serialize(Activity activity, Stream stream);
}
这是我从我的数据库中获取的动态对象,但需要解析它
{{
"details": {
"strength-workout": {
"$type": "LTF.MyPlan.ActivityUtil.Model.Detail.WorkoutDetail, LTF.MyPlan.ActivityUtil",
"type": "Workout",
"workoutId": 94,
"exerciseDetails": [
{
"type": "exercise",
"exerciseID": 36,
"sets": [
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
}
]
},
{
"type": "exercise",
"exerciseID": 46,
"sets": [
{
"reps": 20,
"weight": 4,
"isCompleted": false
},
{
"reps": 20,
"weight": 4,
"isCompleted": false
},
{
"reps": 20,
"weight": 4,
"isCompleted": false
},
{
"reps": 20,
"weight": 4,
"isCompleted": false
},
{
"reps": 20,
"weight": 4,
"isCompleted": false
},
{
"reps": 20,
"weight": 4,
"isCompleted": false
}
]
},
{
"type": "exercise",
"exerciseID": 41,
"sets": [
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
}
]
},
{
"type": "exercise",
"exerciseID": 39,
"sets": [
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
},
{
"reps": 20,
"weight": 0,
"isCompleted": false
}
]
}
]
}
},
"channels": {},
"startTime": "2016-01-20T09:06:44.375836-06:00",
"endTime": "2016-01-20T11:07:25.037335-06:00",
"timerSeconds": 0,
"performer": {
"firstName": "Test",
"nickname": "Test "
}
}}