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

  • Home
  • SEARCH
  • 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 7732303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:41:53+00:00 2026-06-01T06:41:53+00:00

My Code goes like this: using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream())) { string resultString

  • 0

My Code goes like this:

    using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
    {
        string resultString = streamReader1.ReadToEnd();
        var ser = new DataContractJsonSerializer(typeof(RootObject));

        var stream = new MemoryStream(Encoding.Unicode.GetBytes(resultString));
        DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(RootObject));
        RootObject myBook = (RootObject)jsonSerializer.ReadObject(stream);

        Deployment.Current.Dispatcher.BeginInvoke(() => Shops.ItemsSource = myBook.SearchResponse.Spell.Results); }

  public class Query
    {
        public string SearchTerms { get; set; }
    }


    public class Result
    {   [DataMember(IsRequired=false)]
        public string Value { get; set; }
    }

    public class Spell
    {
        [DataMember(IsRequired = false)]
        public int Total { get; set; }
        [DataMember(IsRequired = false)]
        public List<Result> Results { get; set; }
    }

    public class SearchResponse
    {
        public bool IsRequired { get; set; }
        public string Version { get; set; }
        public Query Query { get; set; }
        public Spell Spell { get; set; }
    }

    public class RootObject
    {
        public SearchResponse SearchResponse { get; set; }
    }

IF JSON DATA EXISTS

  {"SearchResponse":{"Version":"2.0","Query":{"SearchTerms":"mispell"},"Spell":{"Total":1,"Results":[{"Value":"misspell"}]}}}

IF JSON DATA DOES NOT EXIST

  {"SearchResponse":{"Version":"2.0","Query":{"SearchTerms":"mispel"}}}

The thing is, if Bing doesn’t detect a wrong word, it crashes and gives me an error like NullReferenceException. I have tried to do an IF statement looking at the stream for if it’s value is blank but doesn’t seem to work.

Any ideas?

  • 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-01T06:41:54+00:00Added an answer on June 1, 2026 at 6:41 am

    If you receive a JSON answer without the Spell part, the Spell property in SearchResponse will be null. If it’s null, you may not dereference it like this:

    myBook.SearchResponse.Spell.Results
    

    (This hasn’t anything to do with JSON. It’s how C# works.)

    So instead of:

    Shops.ItemsSource = myBook.SearchResponse.Spell.Results
    

    you probably want to write:

    if (myBook.SearchResponse.Spell = null)
        Shops.ItemsSource = myBook.SearchResponse.Spell.Results;
    else
        Shops.ItemsSource = new List<Result>();
    

    For your next question: It would be very helpful if your questions would show the exact error message including the stack trace (or at least the exact line where it occurred).

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

Sidebar

Related Questions

I am using the ComboBox in LWUIT. My code goes like this. public Locations(String
Part of my code goes like this: while(1){ my $winmm = new Win32::MediaPlayer; $winmm->load('1.mp3');
The code for the iframe goes like this since I'm using prettyPhoto <a href=stories/story1txt.php?iframe=true&width=400&height=200
I like my code formatted like this: WithDataContext.Execute( delegate(DataContext dataContext) { // code goes
Our projects in TFS are organized like this: $\DefaultCollection\ProjectName\Source <-- source code goes here
I have a bit of php code like this: $test = <!--my comment goes
I am getting time out from using JsonpRequestBuilder. The entry point code goes like
I have a form that contains and form of which code goes like this
I have a code that goes something like: $cipher_alg = MCRYPT_RIJNDAEL_128; $decrypted_string = mcrypt_decrypt($cipher_alg,
Right, this code goes through a rather large multidimensional array (has about 28,000 rows

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.