How to deserialize Multi-Array Json

Oct 20, 2009 at 3:01 PM

Hello every one,My english is very poor,I use the vs2005 and .net2.0,I have a Json string like this:

{"farmlandStatus":[{"a":101,"b":1,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":0,"l":0,"m":0,"n":[],"o":0,"p":[],"q":1256033046,"r":1256033046},{"a":101,"b":1,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":0,"l":0,"m":0,"n":[],"o":0,"p":[],"q":1256033045,"r":1256033045},{"a":14,"b":1,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":0,"l":0,"m":0,"n":[],"o":0,"p":[],"q":1256033041,"r":1256033041},{"a":101,"b":1,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":0,"l":0,"m":0,"n":[],"o":0,"p":[],"q":1256033047,"r":1256033047},{"a":101,"b":1,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":0,"l":0,"m":0,"n":[],"o":0,"p":[],"q":1256033048,"r":1256033048},{"a":14,"b":1,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":0,"l":0,"m":0,"n":[],"o":0,"p":[],"q":1256033042,"r":1256033042},{"a":101,"b":1,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":0,"l":0,"m":0,"n":[],"o":0,"p":[],"q":1256033049,"r":1256033049},{"a":101,"b":1,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":0,"l":0,"m":0,"n":[],"o":0,"p":[],"q":1256033048,"r":1256033048}],"items":{"1":{"itemId":213},"8":{"itemId":80003},"2":{"itemId":12},"4":{"itemId":14},"3":{"itemId":13}},"exp":9115,"dog":{"dogId":3,"isHungry":true},"weather":{"weatherId":3,"weatherDesc":"\u96e8\u5929"},"serverTime":{"time":1256042415},"user":{"uId":33980587,"userName":"astro","money":23107,"headPic":"http:\/\/qlogo4.store.qq.com\/qzonelogo\/33099031\/1\/1244081115","exp":9115,"yellowlevel":0,"yellowstatus":0,"canbad":50,"pf":false},"cacheControl":{"seed":9,"tool":1,"diy":3},"a":false,"b":1256027146,"c":false,"task":{"taskId":0,"taskFlag":0}}

my code like this:

List<userInfo> user = JsonConvert.DeserializeObject<List<userInfo>>(result);

use json.net how to read this json string,pls help me, i really want to know,thank a lot.

error:Expected a JsonObjectContract or JsonDictionaryContract for type 'System.String[]', got 'Newtonsoft.Json.Serialization.JsonArrayContract'.

my written useinfo class like this:

using System;
using System.Collections.Generic;
using System.Text;

namespace AsFarmer
{
    public class userInfo
    {
        private int _a;
        private int _b;
        private int _c;
        private int _d;
        private int _e;
        private int _f;
        private int _g;
        private int _h;
        private int _i;
        private int _j;
        private int _k;
        private int _l;
        private int _m;
        private string[] _n;
        private int _o;
        private string[] _p;
        private int _q;
        private int _r;

        public userInfo() { }

        public userInfo(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, string[] n, int o, string[] p, int q, int r)
        {
            this._a = a;
            this._b = b;
            this._c = c;
            this._d = d;
            this._e = e;
            this._f = f;
            this._g = g;
            this._h = h;
            this._i = i;
            this._j = j;
            this._k = k;
            this._l = l;
            this._m = m;
            this._n = n;
            this._o = o;
            this._p = p;
            this._q = q;
            this._r = r;
        }
        public int a
        {
            get { return _a; }
            set { _a = value; }
        }

        public int b
        {
            get { return _b; }
            set { _b = value; }
        }

        public int c
        {
            get { return _c; }
            set { _c = value; }
        }

        public int d
        {
            get { return _d; }
            set { _d = value; }
        }

        public int e
        {
            get { return _e; }
            set { _e = value; }
        }

        public int f
        {
            get { return _f; }
            set { _f = value; }
        }

        public int g
        {
            get { return _g; }
            set { _g = value; }
        }

        public int h
        {
            get { return _h; }
            set { _h = value; }
        }

        public int i
        {
            get { return _i; }
            set { _i = value; }
        }

        public int j
        {
            get { return _j; }
            set { _j = value; }
        }

        public int k
        {
            get { return _k; }
            set { _k = value; }
        }

        public int l
        {
            get { return _l; }
            set { _l = value; }
        }

        public int m
        {
            get { return _m; }
            set { _m = value; }
        }

        public string[] n
        {
            get { return _n; }
            set { _n = value; }
        }

        public int o
        {
            get { return _o; }
            set { _o = value; }
        }

        public string[] p
        {
            get { return _p; }
            set { _p = value; }
        }

        public int q
        {
            get { return _q; }
            set { _q = value; }
        }

        public int r
        {
            get { return _r; }
            set { _r = value; }
        }

    }
}

 please help me,thanks.

Oct 20, 2009 at 3:07 PM

the other one:

[{"a":7,"b":6,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":21,"l":12,"m":18,"n":{"33980587":1,"414221095":1,"554164531":1},"o":0,"p":[],"q":1255917099,"r":1255978299},{"a":2,"b":6,"c":0,"d":0,"e":1,"f":1,"g":0,"h":1,"i":100,"j":0,"k":16,"l":9,"m":12,"n":{"33980587":1,"414221095":1,"554164531":1,"67640767":1},"o":0,"p":{"1255938367":[6]},"q":1255902667,"r":1255938667},{"a":2,"b":6,"c":0,"d":0,"e":1,"f":1,"g":0,"h":1,"i":100,"j":0,"k":12,"l":7,"m":8,"n":{"33980587":1,"414221095":1,"554164531":1,"67640767":1},"o":0,"p":{"1255938368":[6]},"q":1255902667,"r":1255938667},{"a":2,"b":6,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":13,"l":7,"m":9,"n":{"33980587":1,"414221095":1,"554164531":1,"67640767":1},"o":0,"p":[],"q":1255891867,"r":1255927867},{"a":7,"b":6,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":18,"l":10,"m":15,"n":{"33980587":1,"414221095":1,"554164531":1},"o":0,"p":[],"q":1255917264,"r":1255978464},{"a":3,"b":6,"c":0,"d":0,"e":1,"f":0,"g":0,"h":1,"i":100,"j":0,"k":17,"l":10,"m":13,"n":{"33980587":1,"414221095":1,"554164531":1,"67640767":1},"o":0,"p":[],"q":1255917273,"r":1255964073}]

Coordinator
Oct 24, 2009 at 4:07 AM

n is an array on your object but an object in your JSON.

Nov 2, 2009 at 2:47 AM

n,p like an array but some time like a class,i use the Dictionary<string, object> solve this problem. thk u reply!