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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:08:37+00:00 2026-06-16T01:08:37+00:00

Hi I am creating using Javascript an array of object with a key and

  • 0

Hi I am creating using Javascript an array of object with a key and a value using the following code.

ValuesArray.push({ key: $(this).attr('someattribute'), value: $(this).val() });

As a result I have am array of object like this:

key:29; value: 'Country'
Key:12; value: '4,3,5'

when I am trying to stringify it and send that JSON in a post I am having a wrong formatted JSON with \ and ” in places that I dont want so when I try to desirales that JSON as a JObject on codebehind with C# I am having trouble. How can I create a clean JSON using the stringify

var jObject = JSON.stringify(ValuesArray);

My JSON now which is wrong is:

{
  "JObject": "[{\"key\":\"29\",\"value\":\"Country\"},  {\"key\":\"30\",\"value\":\"4,3,5\"}]"
}

I would like to have a JSON object like this

{
  "JObject": [{"key":"29","value":"Country"},{"key":"30","value":"4,3,5"}]
}

without the quotes around the [] and the character \

Any good idea to solve it.

Thank you

More detail this how I am sending the JSON to my API
this is how I am sending the JSON to my Web API:

function PostAPIRequest(address) {

           var jObject = JSON.stringify(ValuesArray);

           var responseJson = null;
           $.ajax({
               url: address,
               type: 'POST',
               dataType: 'json',
               data: { JObject: jObject },
               success: function (data) {
                   responseJson = data
                   ProcessDataResponse(responseJson);
                   //TODO: REFRESH THE DATA GRID
               },
               error: function (xhr, ajaxOptions, thrownError) {
                   //TODO redirect to the error page and send error email there.
                   alert(xhr.status);
                   alert(thrownError);
               }
           })
       }

and this how I am receiving it in my API controller

...
  // POST api/datavalues/5


   public string Post(int id, JObject  value)
    {
        var temp = value;

...
  • 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-16T01:08:38+00:00Added an answer on June 16, 2026 at 1:08 am

    It looks like you are placing a string as the value in your map. You should do something like:

    var objMap = {"JObject" : ValuesArray};
    var json = JSON.stringify(objMap)

    What’s happening is you are double json encoding your values array – note that your “invalid” JSON value is actually a JSON string rather than the array that you want.

    EDIT
    It looks like you are sticking in JSON strings of maps into an Array and then stringifying that. Here’s a jsfiddle that should help you get what you are looking for – http://jsfiddle.net/4G5nF/

    In your post request, try this

    var jObject = {"JObject" : ValuesArray};
    $.ajax({   url: address,
               type: 'POST',
               dataType: 'json',
               data: jObject,
               success: function (data)  { .. }});
    

    Note the change in the data attribute. That is a value that is automatically JSONified for you.

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

Sidebar

Related Questions

I'm creating the following div using javascript, task_id is an int and person_name is
I am creating date using following code try { newdatetime = new DateTime(2012, 2,
This Javascript logic puzzles me. I'm creating an array and setting the first element
How to declare and initialize an array with key/values using JavaScript and then dynamically
I was creating a countdown timer using javascript; I can use jQuery. I want
I'm starting my hand at creating a multi-player game using HTML 5 / Javascript.
i am dynamically creating radio using jquery as shown belown. but they value only
I am creating package using cmake I am having following structure bin/ bin1 lib/
I'm creating a javascript 2D array from an XML file which I then manipulate
I'm dynamically creating option elements for a drop down menu using Javascript and would

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.