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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:31:42+00:00 2026-06-06T10:31:42+00:00

Is there a nicer way to do this? JavaScriptSerializer jss = new JavaScriptSerializer(); Dictionary<string,

  • 0

Is there a nicer way to do this?

JavaScriptSerializer jss = new JavaScriptSerializer();
Dictionary<string, object> dic =
    jss.Deserialize<Dictionary<string, object>>(json);
Dictionary<string, object>.Enumerator enumerator = dic.GetEnumerator();
enumerator.MoveNext();
ArrayList arr = (ArrayList)enumerator.Current.Value;
foreach (Dictionary<string, object> item in arr)
{
    string compID = item["compID"].ToString();
    string compType = item["compType"].ToString();
}

All I want is my array of items (i.e. comp)

I am sending a json like this:

{ "comps" : [ { compID : 1 , compType : "t" } , { ect. } ] }
  • 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-06T10:31:45+00:00Added an answer on June 6, 2026 at 10:31 am

    Is there a nicer way to do this?

    Yes, by defining models:

    public class MyModel
    {
        public IEnumerable<Comp> Comps { get; set; }
    }
    
    public class Comp
    {
        public int CompId { get; set; }
        public string CompType { get; set; }
    }
    

    and then deserialize the JSON string to this model so that you can work with strong types, not some dictionaries of magic strings:

    JavaScriptSerializer jss = new JavaScriptSerializer();
    MyModel model = jss.Deserialize<MyModel>(json);
    foreach (Comp comp in model.Comps)
    {
        // Do something with comp.CompId and comp.CompType here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a nicer way to write in jUnit String x = foo bar;
Is there a nicer way in jQuery to do this ? $(:text).each(function() { if
Is there a nicer way of doing this? scala> case class A(x : Int)
Is there a nicer way to fill an array with numbers than what I
is there any other simple,nicer way? require 'pp' a1 = [02/28/10,Webinars,131,0,26 Feb 2010,0,3d, 8h,
Is there shorter/nicer way to read input in console as enumerable using standard features
I currently have something like this for my route table. Is there a nicer
Wondering whether there is there a nicer way to detect whether a file was
I overloaded the [] operator in my class. Is there a nicer way to
Not really a problem, but I'm curious if there's a nicer way of doing

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.