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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:37:52+00:00 2026-05-27T08:37:52+00:00

My problem: I’m writing a web app to manage contacts. On the server side,

  • 0

My problem:
I’m writing a web app to manage contacts. On the server side, i’m working with Razor Syntax (C#) and i’m sending ajax requests to my server with a json encoded string as header. The test.cshtml recieves this as follows:

var j = Json.Decode(Request["json"]);

Now i can use all the objects perfectly fine. BUT! I have an array in the json encoded string like...,"persons":[1,2,3],... The Json.Decode decodes this as it should to an array which i can use to write data to my database. After doing this, i’d like to send the updated object back to the client (the array has not been altered or done anything else with) using:

<text>
    @Html.Raw(Json.Encode(j));
    @j.persons.Length;
</text>

and the output of the persons element is ...,"persons":{},..., but the length of persons is 3 as it should be. What am I doing wrong? Are there parameters to tell Json.Encode to encode sub-objects and arrays as well?

Thank you for your support

PS: @j.persons.Length is just to prove the array is not empty and existing

  • 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-27T08:37:53+00:00Added an answer on May 27, 2026 at 8:37 am

    I found the problem. I had to strongly type the automatically generated array (from Json.Decode) with a loop:

    int[] temp = new int[j.persons.Length];
    for(var i = 0;i < j.persons.Length;i++){
        temp[i] = (j.persons[i] is string)?Int32.Parse(j.persons[i]):(int)j.persons[i];
    }
    j.persons = temp;
    

    Thank you for your approach Joseph

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

Sidebar

Related Questions

Problem: We have a web app that calls some web services asynchronously (from the
Problem Statement - Would like to know if particular web app user is active
Problem: Ajax suggest-search on [ n ] ingredients in recipes. That is: match recipes
Problem: Flex/Flash4 client (built with FlashBuilder4) displays the xml sent from the server exactly
Problem: I'm working on a website where there is a dial that displays a
Problem with writing an if-else statement for a sports website. The key is to
Problem: Every time I start a new session of Internet Explorer, the web application
Problem: I want to implement several php-worker processes who are listening on a MQ-server
Problem: I'm making a web service that allows developers to 'register' their Mongoose schemas
Problem: I have an address field from an Access database which has been converted

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.