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 9184257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:00:01+00:00 2026-06-17T19:00:01+00:00

I am getting a json object from an HTTP stream. I create a JObject

  • 0

I am getting a json object from an HTTP stream. I create a JObject using the following:

var stream = await client.GetStreamAsync(uri);
var root = JToken.Load(new JsonTextReader(new StreamReader(stream)));

This gives me the proper response. But now, I want to remove the last element of its results property which is an array (JArray). I use this code:

var results = (JArray)root["results"];
var last = results.Last();              // gets the last element -- correct
var removed = results.Remove(last);     // removed = false and last not removed
var another = last.Remove();            // doesn't work either

I was able to remove a secret property from the root object itself using:

var removed = ((JObject)root).Remove("secret"); // removed = true, works

I can also add elements to the results array, but for some reason, I can’t remove them. What am I missing?

edit: after banging my head against the wall for a couple of hours and writing this post, I found out what was going on. The above code is a simplified version of my actual code. It is that simplification that is the answer actually. The original code was a bit more abbreviated:

var last = root["results"].ToObject<JArray>().Last();
last.Remove();                                         // did not work

The key is that I was mistakenly call ToObject<JArray>(). This broke the remove() logic most likely because the new object is not the same as the original JArray.
So, the posted code works as expected and I have updated my code be simpler too. Sorry for the noise here. A perfect illustration of Rubber Duck Problem Solving

  • 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-17T19:00:03+00:00Added an answer on June 17, 2026 at 7:00 pm

    re-posting here for clarity:

    After banging my head against the wall for a couple of hours and writing this post, I found out what was going on. The above code is a simplified version of my actual code. It is that simplification that is the answer actually. The original code was a bit more abbreviated:

    var last = root["results"].ToObject<JArray>().Last();
    last.Remove();                                         // did not work
    

    The key is that I was mistakenly calling ToObject<JArray>(). This broke the remove() logic most likely because the new object is not the same as the original JArray. So, the posted code works as expected and I have updated my code be simpler too. Sorry for the noise here. A perfect illustration of Rubber Duck Problem Solving
    Thanks to James N-K for both his quick response (on Twitter) and his great library. Thanked him by giving to his project, like Jeff Atwood taught us, more than once.

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

Sidebar

Related Questions

I am getting the JSON request from http://www.viki.com/api/v2/channels.json Now, I have the following classes
So, I'm getting a bunch of string values from a JSON object and then
Hi friends i'm getting json from server (using kohana framework 3.0) like this.... {
I am having trouble getting some data from a JSON object which I have
I am importing JSON data from a public database URI http://data.seattle.gov/api/views/3k2p-39jp/rows.json and the rows
I am trying to post json object {venue:places, US} using below code- HttpClient client
I have a json object that I'm loading from wordpress using the JSON API
I'm getting data from servlet and my sysout of json object which i'm sending
I'm getting the following (str) back from Disqus, JSON expected: ?({code: 0, response: {username:
I am using an example from http://www.androidhive.info/2012/01/android-json-parsing-tutorial/ When I run the application, it says

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.