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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:37:47+00:00 2026-06-07T23:37:47+00:00

{ JsonResult: { List: [{ Subject: Something, Type: 0, TypeDescription: Referral }], } }

  • 0
{
    "JsonResult": {
        "List": [{
            "Subject": "Something",
            "Type": 0,
            "TypeDescription": "Referral"
        }],
     }
}

This is my sample json response i get while hitting my service, after that i have a button which carries option like Subject, Type and TypeDescription.

How can i sort the Json Response based on the parameter i send.

function sortItems(jsonResponse,paramater){
          var sorted =  jsonResponse.List.sort( function(a, b) {
          var nameA = a.paramater.toLowerCase(),
          nameB = b.paramater.toLowerCase();
          return nameA.localeCompare(nameB);
}

Here is the sort function i am using, but its not working. I already have my JSON response and i need to sort at runtime based on the argument i send.

  • 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-07T23:37:49+00:00Added an answer on June 7, 2026 at 11:37 pm

    Here is a Js Fiddle for you which would give you a deeper insight.

    http://jsfiddle.net/spechackers/EdAWL/

    <script type="text/javascript">
            onerror = function (a, b, c) {
                alert([a, b, c]);
            };
        </script>
    <script type="text/javascript">
        var x = {
            "JsonResult": {
                "List": [{
                    "Subject": "My book report on J. K. Rowling's <u>Harry Potter</u> series.",
                    "Date": "Jan 25th 2009",
                    "Type": "Book Report",
                    "Class": "English"
                }, {
                    "Subject": "My book report on Charles Dickens' <u>Oliver Twist</u> novel.",
                    "Date": "May 1st 2003",
                    "Type": "Book Report",
                    "Class": "English"
                }, {
                    "Subject": "My book report on J. R. R. Tolkien's <u>The Lord of the Rings</u> series.",
                    "Date": "Aug 7th 2007",
                    "Type": "Book Report",
                    "Class": "English"
                }, {
                    "Subject": "The civil war in a nutshell.",
                    "Date": "Feb 26th 2009",
                    "Type": "Essay",
                    "Class": "History"
                }, {
                    "Subject": "How does the republican party manage if we life in a democracy?",
                    "Date": "Apr 5th 2010",
                    "Type": "Essay",
                    "Class": "Government"
                }, {
                    "Subject": "A bogus entry",
                    "Date": "Jan 1st 2000",
                    "Type": "Bogus",
                    "Class": "None"
                }, {
                    "Subject": "Zombie followers don't prove anything.",
                    "Date": "Nov 2nd 2004",
                    "Type": "Essay",
                    "Class": "Religion"
                }]
            }
        };
    </script>
    <script type="text/javascript">
        if (typeof Object.prototype.toSource == 'undefined') {
            Object.prototype.toSource = function () {
                return (typeof JSON != 'undefined' && typeof JSON.stringify == 'function') ? JSON.stringify(this) : this.toString();
            };
        }
    
        function sortItems(jsonResponse, paramater) {
            var sorted = jsonResponse.List.sort(
    
            function (a, b) {
                var nameA = a[paramater].toLowerCase();
                var nameB = b[paramater].toLowerCase();
                return nameA.localeCompare(nameB);
            });
            return sorted;
        }
    
        function makeRow(ar) {
            return "<tr><td>" + ar[0] + "</td><td>" + ar[1] + "</td><td>" + ar[2] + "</td><td>" + ar[3] + "</td></tr>";
    
        }
    </script>
    <script type="text/javascript">
        var mySortedList = sortItems(x.JsonResult, "Subject");
        //alert(mySortedList.toSource());
        var outTable = "<table>";
        outTable += "<tr><th>Subject</th><th>Date</th><th>Type</th><th>Class</th></tr>";
        for (var i = 0; i < mySortedList.length; i++) {
            outTable += makeRow([mySortedList[i].Subject, mySortedList[i].Date, mySortedList[i].Type, mySortedList[i].Class]);
        }
        outTable += "</table>";
        document.write(outTable);
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this controller method: public JsonResult List(int number) { var list = new
I'm returning a list of Bookings Class like this: public JsonResult GetEvents() {List<Common.Booking> lst
Im trying to get a list of line items to a webpage using JSON,
I am developing a country state cascading dropdown list... I returned JSON result based
Here is my JsonResult in my controller: // // GET: /Home/GetTags/ public JsonResult GetTags()
My mvc page returns json by using the function Json(mycustomclass) to return a JsonResult
Im geting exception whene the code comes to this part : [GridAction] public JsonResult
In my MVC3 app, I'm using $.ajax to call a method of type JsonResult
I do not understand this error, do not generate error in JsonResult Test (),
how would I return a list of string in a json result in C#

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.