Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:09:58+00:00 2026-06-05T00:09:58+00:00

I am trying to use StackOverflow’s search API to search questions. I am using

  • 0

I am trying to use StackOverflow’s search API to search questions.

I am using this action to perform the parsing :

public ActionResult StackExchange(string sq)
{
    string url = "http://api.stackoverflow.com/1.1/search?intitle=" + sq + "&order=desc";    
    var client = new WebClient();
    var response = client.DownloadString(new Uri(url));
    JObject o = JObject.Parse(response);// ERROR
    int total = (int)o["total"];
    return View(total);
}

Here is the JSON url I am trying to parse:

http://api.stackoverflow.com/1.1/search?intitle=asp.net%20custom%20404&order=desc

I am trying to extract the following data:

`"total": 3` , 
`"question_timeline_url": "/questions/10868557/timeline",`
`"title": "Asp.net custom 404 not working using Intelligencia rewriter"`

Its giving error as : Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: . Path ”, line 0, position 0.

What can be the reason for the exception? I used the same method earlier and it worked fine.

Please suggest.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:09:59+00:00Added an answer on June 5, 2026 at 12:09 am

    Try the following approach.

    Use NuGet and reference the JSON.NET package. I see you’ve already done this.

    Compose a request and get the response.

    string url = "http://api.stackoverflow.com/1.1/search?intitle=test&order=desc";
    var request = (HttpWebRequest) WebRequest.Create(url);
    var response = request.GetResponse();
    

    The response you receive from the Stack Exchange API is gzipped! You first need to unzip it before you can read the JSON response. This is why you are receiving exceptions.

    Let’s create a method which does just that. .NET provides us with the handy GZipStream type for this purpose.

    private string ExtractJsonResponse(WebResponse response)
    {
        string json;
        using (var outStream = new MemoryStream())
        using (var zipStream = new GZipStream(response.GetResponseStream(),
            CompressionMode.Decompress))
       {
            zipStream.CopyTo(outStream);
            outStream.Seek(0, SeekOrigin.Begin);
            using (var reader = new StreamReader(outStream, Encoding.UTF8))
            {
                json = reader.ReadToEnd();
           }
        }
        return json;
    }
    

    Now you can extract the JSON data from the response.

    var json = ExtractJsonResponse(response);
    

    Now you can parse the returned data.

    JObject o = JObject.Parse(json);
    int total = (int)o["total"];
    

    PS: I would recommend you use version 2.0 of the API which has been released earlier this year.

    https://api.stackexchange.com/docs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use some code like is seen on another questions answer: https://stackoverflow.com/a/621849/1044984
I'm trying to use the stackoverflow API and I want to get answers of
In trying to use the stackoverflow api with ajax and jquery and I just
this is my first question in stackoverflow. I am trying to use PHPExcel to
From: https://stackoverflow.com/a/959982/101055 I am trying to use: using System.Text.RegularExpressions; Dictionary<string, string> parameters = new
I'm trying to use the api-stackexchange with java but when I do the request
I was trying use svn to find a checkin using svn log, but it
I'm trying to use Circumflex ORM (as suggested on StackOverflow - here , here
I'm trying to use the new WCF Web API Preview 6 with Basic Authentication.
Im trying to use http://www.javarants.com/2008/04/13/using-google-app-engine-to-extend-yahoo-pipes/ as inspiration, but I'm having some troubles with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.