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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:18:07+00:00 2026-05-26T20:18:07+00:00

Trying to convert a two dimensional array to a two dimensional JSON.Net array. Is

  • 0

Trying to convert a two dimensional array to a two dimensional JSON.Net array.

Is there something wrong with the code below? Or just isn’t this supported by JSON.Net?

        var A = new int[2, 4] { { 1, 1, 1, 1 }, { 2, 2, 2, 2 } };

        Console.WriteLine(JsonConvert.SerializeObject(A));

        // CONSOLE: [1,1,1,1,2,2,2,2]  
        //
        // NB. displays a one dimensional array 
        // instead of two e.g. [[1,1,1,1],[2,2,2,2]]
  • 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-26T20:18:08+00:00Added an answer on May 26, 2026 at 8:18 pm

    Javascript doesn’t have the notion of a 2D array in the same sense that C# does. In order to get an array like that described here, you’ll need to create an array of arrays instead.

    // output: [[1,1,1,1],[2,2,2,2]]
    var a = new int[][] { new[]{ 1, 1, 1, 1 }, new[]{ 2, 2, 2, 2 } };
    

    Update:

    It sounds like JSON.NET now converts multidimensional arrays into an array of arrays in JSON, so the code in the OP will work the same as if you used the code above.

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

Sidebar

Related Questions

I'm trying to convert a two-dimensional array to a string in order to store
I'm trying to convert a two-dimensional array into a structured array with named fields.
Trying to convert this c code into MIPS and run it in SPIM. int
I'm trying to convert two string values into single dict like this string1='red blue
I'm trying to convert Morse code into text. I have two text files to
I am trying to convert the code snippet given in this http://www.movable-type.co.uk/scripts/latlong.html into java.
I am trying to convert this code from Oracle: CREATE VIEW PLANNED AS SELECT
I'm trying to convert some C# code to VB.NET. I have the following in
I am trying to take a two-dimensional array and run it through a series
I'm trying to convert code from Delphi to .Net. I'm stuck on one line:

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.