Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a simple parser to get JSON data from a Web Api Service.

public JSONArray getJSONArrayFromUrl(String url) {
        InputStream is = null;
        JSONArray jObj = null;
        String json = "";
        // Making HTTP request
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(url);

            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"));
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                //json += line;
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }

        // try parse the string to a JSON object
        try {
            jObj = new JSONArray(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON String
        return jObj;

    }

It works but my problem is that when the data is little bigger they get chunked!!!! When the content is smaller everything's working fine, but in other way I get exception like "No value for ".

I used Restlet to query the REST Web Api Service and the exception is

Unterminated array at character 13 of [application/json,UTF-8]

I found some issues about content length in IIS but couldn't find or understand any of the sollutions, someone can help, I definitely think that this is not a client's problem but I think I should focus on server side!

[EDIT]

The JSON I should get:

[
{
$id: "1",
ExamId: 1,
Title: "Agile Part Two",
ClassId: 1,
Description: "Agile Development 202",
Details: "What is Agile software Development? I explain agile with one dozen words: Iterative planning, honest plans, project heartbeat, working software, team ...",
TotalTime: "03:00:00",
RowVersion: "AAAAAAAAD6M=",
Class: null,
Questions: [
{
$id: "2",
QuestionId: 1,
ExamId: 1,
Question1: "You are a coach facilitating retrospective meeting. What is the main purpose of this meeting that facilitator need to ensure during the meeting?",
TimeAverage: "00:10:00",
RowVersion: "AAAAAAAAD6Q=",
Choices: [
{
$id: "3",
ChoiceId: 1,
QuestionId: 1,
Choice1: "Peer pressure, Fine-grain coordination, Focusing on the few, Daily commitment and Raising impediments.",
IsCorrect: true,
Points: 12,
RowVersion: "AAAAAAAAD64=",
Question: {
$ref: "2"
}
},
{
$id: "4",
ChoiceId: 2,
QuestionId: 1,
Choice1: "Know the work, Get a fresh start, Commit to shared goals and Create focus and abundance.",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD7g=",
Question: {
$ref: "2"
}
},
{
$id: "5",
ChoiceId: 3,
QuestionId: 1,
Choice1: "True-up, Show and tell, Get direct feedback, Offer insights and Ask for help.",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD7c=",
Question: {
$ref: "2"
}
},
{
$id: "6",
ChoiceId: 5,
QuestionId: 1,
Choice1: "Inspect and adapt. Look back at how, not what Do (even) better next time.",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD7Y=",
Question: {
$ref: "2"
}
}
],
Exam: {
$ref: "1"
}
},
{
$id: "7",
QuestionId: 2,
ExamId: 1,
Question1: "How does tools like FIT and Fitness compliment Agile?",
TimeAverage: "00:10:00",
RowVersion: "AAAAAAAAD6Y=",
Choices: [
{
$id: "8",
ChoiceId: 6,
QuestionId: 2,
Choice1: "Automated Acceptance Tests",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD7U=",
Question: {
$ref: "7"
}
},
{
$id: "9",
ChoiceId: 7,
QuestionId: 2,
Choice1: "Continuous Integration",
IsCorrect: true,
Points: 15,
RowVersion: "AAAAAAAAD7Q=",
Question: {
$ref: "7"
}
},
{
$id: "10",
ChoiceId: 8,
QuestionId: 2,
Choice1: "Unit Test",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD7k=",
Question: {
$ref: "7"
}
},
{
$id: "11",
ChoiceId: 9,
QuestionId: 2,
Choice1: "Code coverage metrics",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD7o=",
Question: {
$ref: "7"
}
}
],
Exam: {
$ref: "1"
}
},
{
$id: "12",
QuestionId: 3,
ExamId: 1,
Question1: "What does "Timeboxed" means in Agile terms?",
TimeAverage: "00:05:00",
RowVersion: "AAAAAAAAD6g=",
Choices: [
{
$id: "13",
ChoiceId: 10,
QuestionId: 3,
Choice1: "Fast",
IsCorrect: true,
Points: 13,
RowVersion: "AAAAAAAAD7s=",
Question: {
$ref: "12"
}
},
{
$id: "14",
ChoiceId: 11,
QuestionId: 3,
Choice1: "Flexible",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD7w=",
Question: {
$ref: "12"
}
},
{
$id: "15",
ChoiceId: 12,
QuestionId: 3,
Choice1: "Frequent",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD70=",
Question: {
$ref: "12"
}
},
{
$id: "16",
ChoiceId: 13,
QuestionId: 3,
Choice1: "Fixed",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD74=",
Question: {
$ref: "12"
}
}
],
Exam: {
$ref: "1"
}
},
{
$id: "17",
QuestionId: 4,
ExamId: 1,
Question1: "How are EVM metrics used in Agile?",
TimeAverage: "00:15:00",
RowVersion: "AAAAAAAAD6o=",
Choices: [
{
$id: "18",
ChoiceId: 14,
QuestionId: 4,
Choice1: "They are used to prioritize projects.",
IsCorrect: true,
Points: 22,
RowVersion: "AAAAAAAAD78=",
Question: {
$ref: "17"
}
},
{
$id: "19",
ChoiceId: 15,
QuestionId: 4,
Choice1: "They are used to monitor project performance",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD8A=",
Question: {
$ref: "17"
}
},
{
$id: "20",
ChoiceId: 16,
QuestionId: 4,
Choice1: "They are used to analyze risk.",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD8E=",
Question: {
$ref: "17"
}
},
{
$id: "21",
ChoiceId: 17,
QuestionId: 4,
Choice1: "They are used to measure coach's performance.",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD8I=",
Question: {
$ref: "17"
}
}
],
Exam: {
$ref: "1"
}
},
{
$id: "22",
QuestionId: 5,
ExamId: 1,
Question1: "If a team can complete 10 story points in an iteration then how long will it take for the team to complete 100 story points?",
TimeAverage: "00:12:00",
RowVersion: "AAAAAAAAD6w=",
Choices: [
{
$id: "23",
ChoiceId: 19,
QuestionId: 5,
Choice1: "10 Iterations",
IsCorrect: true,
Points: 11,
RowVersion: "AAAAAAAAD8Q=",
Question: {
$ref: "22"
}
},
{
$id: "24",
ChoiceId: 20,
QuestionId: 5,
Choice1: "10 waves",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD8U=",
Question: {
$ref: "22"
}
},
{
$id: "25",
ChoiceId: 21,
QuestionId: 5,
Choice1: "20 Iterations",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD8Y=",
Question: {
$ref: "22"
}
},
{
$id: "26",
ChoiceId: 23,
QuestionId: 5,
Choice1: "20 waves",
IsCorrect: false,
Points: 0,
RowVersion: "AAAAAAAAD8g=",
Question: {
$ref: "22"
}
}
],
Exam: {
$ref: "1"
}
}
],
Schedule: {
$id: "27",
ScheduleId: 1,
DateScheduled: "2013-03-06T00:00:00",
RowVersion: "AAAAAAAAD8k=",
Exam: {
$ref: "1"
}
}
}
]

The JSON I Get:

[{"ClassId":1,"Description":"Agile Development 202","Schedule":{"RowVersion":"AAAAAAAAD8k=","Exam":{"$ref":"1"},"DateScheduled":"2013-03-06T00:00:00","ScheduleId":1,"$id":"27"},"Questions":[{"Exam":{"$ref":"1"},"RowVersion":"AAAAAAAAD6Q=","Choices":[{"Question":{"$ref":"2"},"RowVersion":"AAAAAAAAD64=","QuestionId":1,"IsCorrect":true,"ChoiceId":1,"Points":12,"$id":"3","Choice1":"Peer pressure, Fine-grain coordination, Focusing on the few, Daily commitment and Raising impediments."},{"Question":{"$ref":"2"},"RowVersion":"AAAAAAAAD7g=","QuestionId":1,"IsCorrect":false,"ChoiceId":2,"Points":0,"$id":"4","Choice1":"Know the work, Get a fresh start, Commit to shared goals and Create focus and abundance."},{"Question":{"$ref":"2"},"RowVersion":"AAAAAAAAD7c=","QuestionId":1,"IsCorrect":false,"ChoiceId":3,"Points":0,"$id":"5","Choice1":"True-up, Show and tell, Get direct feedback, Offer insights and Ask for help."},{"Question":{"$ref":"2"},"RowVersion":"AAAAAAAAD7Y=","QuestionId":1,"IsCorrect":false,"ChoiceId":5,"Points":0,"$id":"6","Choice1":"Inspect and adapt. Look back at how, not what\r\nDo (even) better next time."}],"QuestionId":1,"TimeAverage":"00:10:00","ExamId":1,"Question1":"You are a coach facilitating retrospective meeting. What is the main purpose of this meeting that facilitator need to ensure during the meeting?","$id":"2"},{"Exam":{"$ref":"1"},"RowVersion":"AAAAAAAAD6Y=","Choices":[{"Question":{"$ref":"7"},"RowVersion":"AAAAAAAAD7U=","QuestionId":2,"IsCorrect":false,"ChoiceId":6,"Points":0,"$id":"8","Choice1":"Automated Acceptance Tests"},{"Question":{"$ref":"7"},"RowVersion":"AAAAAAAAD7Q=","QuestionId":2,"IsCorrect":true,"ChoiceId":7,"Points":15,"$id":"9","Choice1":"Continuous Integration"},{"Question":{"$ref":"7"},"RowVersion":"AAAAAAAAD7k=","QuestionId":2,"IsCorrect":false,"ChoiceId":8,"Points":0,"$id":"10","Choice1":"Unit Test"},{"Question":{"$ref":"7"},"RowVersion":"AAAAAAAAD7o=","QuestionId":2,"IsCorrect":false,"ChoiceId":9,"Points":0,"$id":"11","Choice1":"Code coverage metrics"}],"QuestionId":2,"TimeAverage":"00:10:00","ExamId":1,"Question1":"How does tools like FIT and Fitness compliment Agile?","$id":"7"},{"Exam":{"$ref":"1"},"RowVersion":"AAAAAAAAD6g=","Choices":[{"Question":{"$ref":"12"},"RowVersion":"AAAAAAAAD7s=","QuestionId":3,"IsCorrect":true,"ChoiceId":10,"Points":13,"$id":"13","Choice1":"Fast"},{"Question":{"$ref":"12"},"RowVersion":"AAAAAAAAD7w=","QuestionId":3,"IsCorrect":false,"ChoiceId":11,"Points":0,"$id":"14","Choice1":"Flexible"},{"Question":{"$ref":"12"},"RowVersion":"AAAAAAAAD70=","QuestionId":3,"IsCorrect":false,"ChoiceId":12,"Points":0,"$id":"15","Choice1":"Frequent"},{"Question":{"$ref":"12"},"RowVersion":"AAAAAAAAD74=","QuestionId":3,"IsCorrect":false,"ChoiceId":13,"Points":0,"$id":"16","Choice1":"Fixed"}],"QuestionId":3,"TimeAverage":"00:05:00","ExamId":1,"Question1":"What does \"Timeboxed\" means in Agile terms?","$id":"12"},{"Exam":{"$ref":"1"},"RowVersion":"AAAAAAAAD6o=","Choices":[{"Question":{"$ref":"17"},"RowVersion":"AAAAAAAAD78=","QuestionId":4,"IsCorrect":true,"ChoiceId":14,"Points":22,"$id":"18","Choice1":"They are used to prioritize projects."},{"Question":{"$ref":"17"},"RowVersion":"AAAAAAAAD8A=","QuestionId":4,"IsCorrect":false,"ChoiceId":15,"Points":0,"$id":"19","Choice1":"They are used to monitor project performance"},{"Question":{"$ref":"17"},"RowVersion":"AAAAAAAAD8E=","QuestionId":4,"IsCorrect":false,"ChoiceId":16,"Points":0,"$id":"20","Choice1":"They are used to analyze risk."},{"Question":{"$ref":"17"},"RowVersion":"AAAAAAAAD8I=","QuestionId":4,"IsCorrect":false,"ChoiceId":17,"Points":0,"$id":"21","Choice1":"They are used to measure coach's performance."}],"QuestionId":4,"TimeAverage":"00:15:00","ExamId":1,"Question1":"How are EVM metrics used in Agile?","$id":"17"},{"Exam":{"$ref":"1"},"RowVersion":"AAAAAAAAD6w=","Choices":[{"Question":{"$ref":"22"},"RowVersion":"AAAAAAAAD8Q=","QuestionId":5,"IsCorrect":true,"ChoiceId":19,"Points":11,"$id":"23","Choice1":"10 Iterations"},{"Question":{"$ref":"22"},"RowVersion":"AAA

Thank you in advance.

share|improve this question
 
can you share your json array response if possible? –  Siddhesh Mar 7 '13 at 13:59
 
Edited the question with your request –  Taskos George Mar 7 '13 at 14:14
add comment

2 Answers

[
    {
        "ClassId": 1,
        "Description": "Agile Development 202",
        "Schedule": {
            "RowVersion": "AAAAAAAAD8k=",
            "Exam": {
                "$ref": "1"
            },
            "DateScheduled": "2013-03-06T00:00:00",
            "ScheduleId": 1,
            "$id": "27"
        },
        "Questions": [
            {
                "Exam": {
                    "$ref": "1"
                },
                "RowVersion": "AAAAAAAAD6Q=",
                "Choices": [
                    {
                        "Question": {
                            "$ref": "2"
                        },
                        "RowVersion": "AAAAAAAAD64=",
                        "QuestionId": 1,
                        "IsCorrect": true,
                        "ChoiceId": 1,
                        "Points": 12,
                        "$id": "3",
                        "Choice1": "Peer pressure, Fine-grain coordination, Focusing on the few, Daily commitment and Raising impediments."
                    },
                    {
                        "Question": {
                            "$ref": "2"
                        },
                        "RowVersion": "AAAAAAAAD7g=",
                        "QuestionId": 1,
                        "IsCorrect": false,
                        "ChoiceId": 2,
                        "Points": 0,
                        "$id": "4",
                        "Choice1": "Know the work, Get a fresh start, Commit to shared goals and Create focus and abundance."
                    },
                    {
                        "Question": {
                            "$ref": "2"
                        },
                        "RowVersion": "AAAAAAAAD7c=",
                        "QuestionId": 1,
                        "IsCorrect": false,
                        "ChoiceId": 3,
                        "Points": 0,
                        "$id": "5",
                        "Choice1": "True-up, Show and tell, Get direct feedback, Offer insights and Ask for help."
                    },
                    {
                        "Question": {
                            "$ref": "2"
                        },
                        "RowVersion": "AAAAAAAAD7Y=",
                        "QuestionId": 1,
                        "IsCorrect": false,
                        "ChoiceId": 5,
                        "Points": 0,
                        "$id": "6",
                        "Choice1": "Inspect and adapt. Look back at how, not what\r\nDo (even) better next time."
                    }
                ],
                "QuestionId": 1,
                "TimeAverage": "00:10:00",
                "ExamId": 1,
                "Question1": "You are a coach facilitating retrospective meeting. What is the main purpose of this meeting that facilitator need to ensure during the meeting?",
                "$id": "2"
            },
            {
                "Exam": {
                    "$ref": "1"
                },
                "RowVersion": "AAAAAAAAD6Y=",
                "Choices": [
                    {
                        "Question": {
                            "$ref": "7"
                        },
                        "RowVersion": "AAAAAAAAD7U=",
                        "QuestionId": 2,
                        "IsCorrect": false,
                        "ChoiceId": 6,
                        "Points": 0,
                        "$id": "8",
                        "Choice1": "Automated Acceptance Tests"
                    },
                    {
                        "Question": {
                            "$ref": "7"
                        },
                        "RowVersion": "AAAAAAAAD7Q=",
                        "QuestionId": 2,
                        "IsCorrect": true,
                        "ChoiceId": 7,
                        "Points": 15,
                        "$id": "9",
                        "Choice1": "Continuous Integration"
                    },
                    {
                        "Question": {
                            "$ref": "7"
                        },
                        "RowVersion": "AAAAAAAAD7k=",
                        "QuestionId": 2,
                        "IsCorrect": false,
                        "ChoiceId": 8,
                        "Points": 0,
                        "$id": "10",
                        "Choice1": "Unit Test"
                    },
                    {
                        "Question": {
                            "$ref": "7"
                        },
                        "RowVersion": "AAAAAAAAD7o=",
                        "QuestionId": 2,
                        "IsCorrect": false,
                        "ChoiceId": 9,
                        "Points": 0,
                        "$id": "11",
                        "Choice1": "Code coverage metrics"
                    }
                ],
                "QuestionId": 2,
                "TimeAverage": "00:10:00",
                "ExamId": 1,
                "Question1": "How does tools like FIT and Fitness compliment Agile?",
                "$id": "7"
            },
            {
                "Exam": {
                    "$ref": "1"
                },
                "RowVersion": "AAAAAAAAD6g=",
                "Choices": [
                    {
                        "Question": {
                            "$ref": "12"
                        },
                        "RowVersion": "AAAAAAAAD7s=",
                        "QuestionId": 3,
                        "IsCorrect": true,
                        "ChoiceId": 10,
                        "Points": 13,
                        "$id": "13",
                        "Choice1": "Fast"
                    },
                    {
                        "Question": {
                            "$ref": "12"
                        },
                        "RowVersion": "AAAAAAAAD7w=",
                        "QuestionId": 3,
                        "IsCorrect": false,
                        "ChoiceId": 11,
                        "Points": 0,
                        "$id": "14",
                        "Choice1": "Flexible"
                    },
                    {
                        "Question": {
                            "$ref": "12"
                        },
                        "RowVersion": "AAAAAAAAD70=",
                        "QuestionId": 3,
                        "IsCorrect": false,
                        "ChoiceId": 12,
                        "Points": 0,
                        "$id": "15",
                        "Choice1": "Frequent"
                    },
                    {
                        "Question": {
                            "$ref": "12"
                        },
                        "RowVersion": "AAAAAAAAD74=",
                        "QuestionId": 3,
                        "IsCorrect": false,
                        "ChoiceId": 13,
                        "Points": 0,
                        "$id": "16",
                        "Choice1": "Fixed"
                    }
                ],
                "QuestionId": 3,
                "TimeAverage": "00:05:00",
                "ExamId": 1,
                "Question1": "What does \"Timeboxed\" means in Agile terms?",
                "$id": "12"
            },
            {
                "Exam": {
                    "$ref": "1"
                },
                "RowVersion": "AAAAAAAAD6o=",
                "Choices": [
                    {
                        "Question": {
                            "$ref": "17"
                        },
                        "RowVersion": "AAAAAAAAD78=",
                        "QuestionId": 4,
                        "IsCorrect": true,
                        "ChoiceId": 14,
                        "Points": 22,
                        "$id": "18",
                        "Choice1": "They are used to prioritize projects."
                    },
                    {
                        "Question": {
                            "$ref": "17"
                        },
                        "RowVersion": "AAAAAAAAD8A=",
                        "QuestionId": 4,
                        "IsCorrect": false,
                        "ChoiceId": 15,
                        "Points": 0,
                        "$id": "19",
                        "Choice1": "They are used to monitor project performance"
                    },
                    {
                        "Question": {
                            "$ref": "17"
                        },
                        "RowVersion": "AAAAAAAAD8E=",
                        "QuestionId": 4,
                        "IsCorrect": false,
                        "ChoiceId": 16,
                        "Points": 0,
                        "$id": "20",
                        "Choice1": "They are used to analyze risk."
                    },
                    {
                        "Question": {
                            "$ref": "17"
                        },
                        "RowVersion": "AAAAAAAAD8I=",
                        "QuestionId": 4,
                        "IsCorrect": false,
                        "ChoiceId": 17,
                        "Points": 0,
                        "$id": "21",
                        "Choice1": "They are used to measure coach's performance."
                    }
                ],
                "QuestionId": 4,
                "TimeAverage": "00:15:00",
                "ExamId": 1,
                "Question1": "How are EVM metrics used in Agile?",
                "$id": "17"
            },
            {
                "Exam": {
                    "$ref": "1"
                },
                "RowVersion": "AAAAAAAAD6w=",
                "Choices": [
                    {
                        "Question": {
                            "$ref": "22"
                        },
                        "RowVersion": "AAAAAAAAD8Q=",
                        "QuestionId": 5,
                        "IsCorrect": true,
                        "ChoiceId": 19,
                        "Points": 11,
                        "$id": "23",
                        "Choice1": "10 Iterations"
                    },
                    {
                        "Question": {
                            "$ref": "22"
                        },
                        "RowVersion": "AAA

as i can see your json is not properly formated and your array is not closed so you are getting error Unterminated array

share|improve this answer
 
I know that this is my problem, but if you compare the two JSON data are so innapropriate to each other, and this shouldn't happen....I use Web Api and I don't know why it behaves this way....any thoughts on client / server? –  Taskos George Mar 7 '13 at 14:19
add comment

Solved the issue with disabling chunked encoding.

See details in this answer

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.