Reading values from a JSON response.

SeanSean AUMember

HI There, I'm wanting to return some of the values in my JSON response. I'm able to process the response but I'm not able to access the response properly. I have a sample response below for which I'd like to access the values of the questions.

Can someone help with this please?

Thanks in advance.

{
"total": 4314,
"page": 1,
"pagesize": 30,
"questions": [
{
"tags": [
"monotouch",
"google-maps-sdk-ios"
],
"answer_count": 2,
"favorite_count": 0,
"question_timeline_url": "/questions/15027405/timeline",
"question_comments_url": "/questions/15027405/comments",
"question_answers_url": "/questions/15027405/answers",
"question_id": 15027405,
"owner": {
"user_id": 82586,
"user_type": "registered",
"display_name": "James",
"reputation": 20318,
"email_hash": "d5445b4fe86d7c01add3e1012075a882"
},
"creation_date": 1361546537,
"last_edit_date": 1361619824,
"last_activity_date": 1361948632,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 100,
"score": 0,
"community_owned": false,
"title": "Google Maps SDK for iOS crashing on startup using Monotouch bindings"
},
{
"tags": [
"binding",
"monotouch"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/15104875/timeline",
"question_comments_url": "/questions/15104875/comments",
"question_answers_url": "/questions/15104875/answers",
"question_id": 15104875,
"owner": {
"user_id": 367427,
"user_type": "registered",
"display_name": "Christian",
"reputation": 52,
"email_hash": "c896da595a2793a26eadd61dace007ed"
},
"creation_date": 1361943080,
"last_edit_date": 1361944129,
"last_activity_date": 1361944129,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 8,
"score": 0,
"community_owned": false,
"title": "How can bind property block monotouch"
},
{
"tags": [
"monotouch",
"core-plot",
"xamarin-studio"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/15042115/timeline",
"question_comments_url": "/questions/15042115/comments",
"question_answers_url": "/questions/15042115/answers",
"question_id": 15042115,
"owner": {
"user_id": 1030166,
"user_type": "registered",
"display_name": "Obiwan007",
"reputation": 172,
"email_hash": "7937fe6c1001355bda3b96bae16b1328"
},
"creation_date": 1361633061,
"last_activity_date": 1361633061,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 40,
"score": 0,
"community_owned": false,
"title": "Core-Plot with Xamarin MonoTouch / Xamarin Studio"
},
{
"tags": [
"ios",
"monotouch"
],
"answer_count": 1,
"favorite_count": 0,
"question_timeline_url": "/questions/15033727/timeline",
"question_comments_url": "/questions/15033727/comments",
"question_answers_url": "/questions/15033727/answers",
"question_id": 15033727,
"owner": {
"user_id": 1121957,
"user_type": "registered",
"display_name": "BRogers",
"reputation": 119,
"email_hash": "b5b31b020c7bc3f71448d31bc9ab241b"
},
"creation_date": 1361569561,
"last_activity_date": 1361626411,
"up_vote_count": 1,
"down_vote_count": 0,
"view_count": 17,
"score": 1,
"community_owned": false,
"title": "Monotouch Importing Contact - Return Type Issue"
}
]
}

!-------

            JsonArray jsonArray = new JsonArray(this.GetJsonObject ());
            List<String> list = new List<String>();
            for (int i = 0; i < jsonArray.Count; i++) {
                Console.WriteLine(jsonArray["questions"].ToString());

            }

private JsonValue GetJsonObject ()
{

        string responseString = string.Empty;

        Uri uri = new Uri ("http://localhost/complex-json.json");
        HttpWebRequest request = new HttpWebRequest (uri);
        request.Method = "GET";


        HttpWebResponse response = request.GetResponse () as HttpWebResponse;
        using (StreamReader sr = new StreamReader(response.GetResponseStream())) {
            responseString = sr.ReadToEnd ();
        }
        response.Close ();
        return JsonValue.Parse (responseString);    
    }

Posts

Sign In or Register to comment.