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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:21:32+00:00 2026-06-13T01:21:32+00:00

I have following code in Generic Handler of Asp.net: var students= Student.GetStudents(); var result

  • 0

I have following code in Generic Handler of Asp.net:

    var students= Student.GetStudents();
    var result = new
    {
        Data = students.Select(s => new []{s.subjects})              
    };

    var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    var json = serializer.Serialize(result);                
    context.Response.ContentType = "application/json";
    context.Response.Write(json);

Applied on the Class Student:

public class Student
{
    public List<String> subjects{get; set;}

    Student()
    {
        subjects= new List<string>();
    }    

    public static IEnumerable<Student> GetStudents()
    {       
        List<Student> students= new List<Student>();

        Student s1 = new Student();
        s1.subjects.Add("Trigonometry");
        s1.subjects.Add("Chemistry");
        students.Add(row1);

        Student s2 = new Student();
        s2.subjects.Add("Physics");
        s2.subjects.Add("Biology");
        students.Add(s2);

        return students;
   }
}

which gives me output as:

{"Data":[[["Trigonometry","Chemistry"]],[["Physics","Biology"]]]}

But I want it in following format:

{"Data":[["Trigonometry","Chemistry"],["Physics","Biology"]]}

How JavaScriptSerializer works?
Why is it creating another array?
What should I do to fix this?

  • 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-13T01:21:33+00:00Added an answer on June 13, 2026 at 1:21 am

    Its not perfect but working for me:

    var rows = Row.GetRows();
    StringBuilder sb = new StringBuilder("\"aaData\":[");
    
    for (int i = 0; i < rows.Count; i++)
    {
        if (i == 0){  sb.Append("[");  }
        else  {  sb.Append(",[");  }
        for (int j = 0; j < rows[i].fields.Count; j++)
        {
            if (j == 0){
                sb.Append("\"" + rows[i].fields[j].ToString() + "\"");
            }
            else{
                sb.Append(",\"" + rows[i].fields[j].ToString() + "\"");
            }
        }
        sb.Append("]");            
    }
    sb.Append("]}");
    
    var json = sb.ToString();
    
    context.Response.ContentType = "application/json";
    context.Response.Write(json);
    

    Since the JavaScriptSerializer adding one more [] to the json object, I tried not to use it and create the json string manually.

    Let me know the pros and cons of using this way.

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

Sidebar

Related Questions

I have the following code implementation of my generic singleton provider: public sealed class
I have the following code using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace
I have following code for inserting data into database using PDO. It inserts data
I have following code that I am compiling in a .NET 4.0 project namespace
I currently have the following code that retrieves data from the database and then
I have the following generic code: public V put(K key, V value){ Object o
I have the following piece of code on C#, on an ASHX or Generic
I have the following .cs file; using System; using System.Collections.Generic; using Sitecore.Data; using Sitecore.Data.Items;
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>

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.