Tag Archives: Jsonreader Error

How to parse JSON string in.Net [error reading job object from jsonreader. Current jsonreader item is not an obj]

Edit time: 2017-05-10. Add a method to transform list
First, I know a way to parse JSON string before, I find it a little troublesome. I got another one from somewhere else

string json = vlt.getlist();

JObject jo = JObject.Parse(json);

var data = jo.getValue("data").ToObject<T>();

T is the corresponding entity class, and can be used directly in the member variable data.member
2. Json transformation of the List is to put it into redIS cache, and then take it out for transformation
Don’t talk nonsense, code on:

            var t = new List<PcWareListByCourseId>();
            var m1 = new PcWareListByCourseId
            {
                videoId = 12,
                IsAuditions = false,
                percent = 23,
                practiceId = 43,
                statuss = 2,
                TotalTime = "12.2",
                wareId = 22,
                wareName = "courseware"
            };
            var m2 = new PcWareListByCourseId
            {
                videoId = 12,
                IsAuditions = false,
                percent = 23,
                practiceId = 43,
                statuss = 2,
                TotalTime = "12.2",
                wareId = 22,
                wareName = "courseware"
            };
            t.Add(m1);
            t.Add(m2);
            RedisInfoHelper.SetRedis("test",t);

            var get = RedisInfoHelper.GetRedisValue("test");

            var jo = JArray.Parse(get);
            var jj = jo.ToObject<List<PcWareListByCourseId>>();

Entity code:

    public class PcWareListByCourseId
    {
        public int wareId { set; get; }
        public string wareName { set; get; }
        public bool IsAuditions { set; get; }
        public int videoId { set; get; }
        public int percent { set; get; }
        public int practiceId { set; get; }
        public int statuss { set; get; }
        public string TotalTime { set; get; }//11'22"
    }



Successful to the last step, successful transformation.
This time I’m using the JArray method class.