servlet

时间:2016-06-20 06:05:39

标签: java json

我将这个嵌套的json数组数据发送到servlet。现在我想在servlet中迭代这个json数据。 json数据是:

/* 1 */
{
    "_id" : ObjectId("5761c22edd93e211f49d5d51"),
    "fullName" : "Mohammad Amir",
    "enroll" : "abc123",
    "email" : "amir.fragrance@gmail.com",
    "mobile" : "8090370605",
    "password" : "$2a$12$RTSx6T8SyY9d8d16HpgatuEUHwRBi60PZslCWvSGojNJSx21HKQuK",
    "registeredOn" : ISODate("2016-06-15T21:01:34.736Z"),
    "profile" : {
        "isCompleted" : true,
        "verification" : [ 
            {
                "provost" : false,
                "verifiedBy" : "Director Computer Centre",
                "verifiedOn" : ISODate("2016-06-16T21:57:51.088Z")
            }, 
            {
                "chairman" : false,
                "verifiedBy" : null,
                "verifiedOn" : null
            }
        ],
        "isChecked" : false,
        "fullName" : "Mohammad Amir",
        "enroll" : "abc123",
        "fatherName" : "jhgjgjh",
        "motherName" : "kghjhgj",
        "dob" : "2016-06-14T18:30:00.000Z",
        "gender" : "Male",
        "address" : "ytiutit",
        "city" : "Abdul",
        "state" : "Andaman and Nicobar Islands",
        "country" : "Afghanistan",
        "pincode" : "76575",
        "courseType" : "UG",
        "courseName" : "Adv Dip in Int.Decoration",
        "semesterYear" : 1,
        "facultyNumber" : "765gvjn",
        "department" : "Agricultural Eco. Business Mngt.",
        "hall" : "Abdullah Hall"
    },
    "contact" : {
        "emailID" : {
            "isVerified" : false,
            "isChecked" : false
        },
        "mobileID" : {
            "isVerified" : false,
            "isChecked" : false
        }
    }
}

/* 2 */
{
    "_id" : ObjectId("5761c2d2dd93e211f49d5d5e"),
    "fullName" : "Bilal Khan",
    "enroll" : "abc1",
    "email" : "bilal.khan@gmail.com",
    "mobile" : "9456789799",
    "password" : "$2a$12$rK7oZCK6Gb7vrxUcOCOsaOWVrB2D.eZFj35Yu5wxB.3ueC6G7dJ.q",
    "registeredOn" : ISODate("2016-06-15T21:04:18.796Z"),
    "profile" : {
        "isCompleted" : true,
        "verification" : [ 
            {
                "provost" : false,
                "verifiedBy" : "Director Computer Centre",
                "verifiedOn" : ISODate("2016-06-16T22:00:30.263Z")
            }, 
            {
                "chairman" : false,
                "verifiedBy" : null,
                "verifiedOn" : null
            }
        ],
        "isChecked" : false,
        "fullName" : "Bilal Khan",
        "enroll" : "abc1",
        "fatherName" : "kjfshdhjg",
        "motherName" : "jhgjhg",
        "dob" : "2016-06-14T18:30:00.000Z",
        "gender" : "Male",
        "address" : "kjhkjhkj",
        "city" : "Hadadi",
        "state" : "Andaman and Nicobar Islands",
        "country" : "Afghanistan",
        "pincode" : "76575",
        "courseType" : "UG",
        "courseName" : "Adv Dip in Int.Decoration",
        "semesterYear" : 1,
        "facultyNumber" : "76567",
        "department" : "Agricultural Eco. Business Mngt.",
        "hall" : "Abdullah Hall"
    },
    "contact" : {
        "emailID" : {
            "isVerified" : false,
            "isChecked" : false
        },
        "mobileID" : {
            "isVerified" : false,
            "isChecked" : false
        }
    }
}

我在servlet中尝试这个

StringBuilder sb = new StringBuilder();
        BufferedReader br = request.getReader();
        String str = null;
        while ((str = br.readLine()) != null) {
            sb.append(str);
        }
        JSONObject jObj = new JSONObject(sb.toString());
        boolean value = jObj.getBoolean("profile.verification[0].provost");
        response.getWriter().write("value: " + value);

但是得到了这个错误。我想迭代每个文档。在这种情况下,我有2个文件。如何迭代每个文档并遍历嵌套数组。这是错误.................... org.json.JSONException:JSONObject文本必须以' {'在1 [字符2第1行]

0 个答案:

没有答案