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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:48:47+00:00 2026-05-21T02:48:47+00:00

I have a JSON.NET JObject with data structured like this: { foo : {

  • 0

I have a JSON.NET JObject with data structured like this:

{
    "foo" : {
        "bar": "baz"
    }
}

I’m trying to convert it to a ASP.NET MVC JsonResult as follows:

JObject someData = ...;
JsonResult jsonResult = Json(someData, "application/json", JsonRequestBehavior.AllowGet);

When I do this, I get the following exception:

InvalidOperationException was
unhandled by user code. Cannot access
child value on
Newtonsoft.Json.Linq.JValue.

I have a workaround, in that I can iterate through all of the properties of the JObject, and parse them into a generic object like so:

JsonResult jsonResult = Json(new { key1 = value1, key2 = value2, ... });

However, this seems error prone and like an unnecessary non-generic way of solving this problem. Is there any way I can do this more efficiently, hopefully using some built in methods in JSON.NET or ASP.NET MVC?

  • 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-05-21T02:48:48+00:00Added an answer on May 21, 2026 at 2:48 am

    If you have a JObject I would recommend you writing a custom ActionResult which directly serializes this JObject using JSON.NET into the response stream. It is more in the spirit of the MVC pattern:

    public ActionResult Foo()
    {
        JObject someData = ...;
        return new JSONNetResult(someData);
    }
    

    where:

    public class JSONNetResult: ActionResult
    {
        private readonly JObject _data;
        public JSONNetResult(JObject data)
        {
            _data = data;
        }
    
        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;
            response.ContentType = "application/json";
            response.Write(_data.ToString(Newtonsoft.Json.Formatting.None));
        }
    }
    

    It seems like an overkill to have a JObject which you would serialize into JSON using the .NET JavaScriptSerializer which is more commonly used in conjunction with some model classes.

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

Sidebar

Related Questions

I have a JObject (I'm using Json.Net) that I constructed with LINQ to JSON
I have set up jqGrid with JSON in my .Net MVC project. The grid
I am trying to parse a Json file like this, generated by Exiftool: [{
I have a ASP.net MVC application that gets marker coordinates from a database (I
I have a JSON result that contains numerous records. I'd like to show the
Im trying to use JSON.NET framework in a windows Form to read some information
Is there any way to have Json.net serialize an object directly to a NetworkStream?
I have this JSON string: { success:true,user_id:309,id:309,sessId:false,email:null,name:Mai Van Quan,username:quanmv,role:Reseller Admin,messages:,org_name:null,microPayNumber:4949,microPayWord:neocam,mobile:null,permissions:{ADD_CAMERA:true, REMOVE_CAMERA:true, EDIT_CAM_GENERAL:true, ACCESS_CAM_TECHNICAL:true, EDIT_CAM_PKG:true,
I have passed some JSON to my page via a webservice. I used JSON.NET
Is there a way to use the lift-json library's JObject class to act like

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.