Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Hashtable within Hashtable

Hashtable within Hashtable

Scheduled Pinned Locked Moved C#
jsonhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michael_jhons
    wrote on last edited by
    #1

    hello everybody, i'm retreiving data(API) with JSON format and i'm parsing it inside a hashtable, it seems like some specific keys have a value= hashtable(or arraylist!) below is how i'm extractin the the first layer value

    foreach (object objResult in jsonResults)
    {
    Hashtable jsonResult = (Hashtable)objResult;
    dt.Rows.Add(jsonResult["city"].ToString(), jsonResult["reviews"].ToString(), jsonResult["avg_rating"].ToString(), jsonResult["rating_img_url"].ToString());
    }

    the problem is where the values are equal to arraylist i'm not able to extract them Is there any way to extract the second layer keys and values? (btw i'm very new to hashtables and arraylists) Thank you in advance

    A _ 2 Replies Last reply
    0
    • M michael_jhons

      hello everybody, i'm retreiving data(API) with JSON format and i'm parsing it inside a hashtable, it seems like some specific keys have a value= hashtable(or arraylist!) below is how i'm extractin the the first layer value

      foreach (object objResult in jsonResults)
      {
      Hashtable jsonResult = (Hashtable)objResult;
      dt.Rows.Add(jsonResult["city"].ToString(), jsonResult["reviews"].ToString(), jsonResult["avg_rating"].ToString(), jsonResult["rating_img_url"].ToString());
      }

      the problem is where the values are equal to arraylist i'm not able to extract them Is there any way to extract the second layer keys and values? (btw i'm very new to hashtables and arraylists) Thank you in advance

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      Yes. You need to access the second level values using their keys and then putting them into your string. e.g. Dictionary x = (Dictionary)jsonResult["reviews"]; string res = x["mySecondLevelReviews"].ToString();

      The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.

      M 1 Reply Last reply
      0
      • M michael_jhons

        hello everybody, i'm retreiving data(API) with JSON format and i'm parsing it inside a hashtable, it seems like some specific keys have a value= hashtable(or arraylist!) below is how i'm extractin the the first layer value

        foreach (object objResult in jsonResults)
        {
        Hashtable jsonResult = (Hashtable)objResult;
        dt.Rows.Add(jsonResult["city"].ToString(), jsonResult["reviews"].ToString(), jsonResult["avg_rating"].ToString(), jsonResult["rating_img_url"].ToString());
        }

        the problem is where the values are equal to arraylist i'm not able to extract them Is there any way to extract the second layer keys and values? (btw i'm very new to hashtables and arraylists) Thank you in advance

        _ Offline
        _ Offline
        _Erik_
        wrote on last edited by
        #3

        Since your data seems to be in JSON format, you might want to use JsonReaderWriterFactory[^] class. It will become much easier to parse.

        1 Reply Last reply
        0
        • A Abhinav S

          Yes. You need to access the second level values using their keys and then putting them into your string. e.g. Dictionary x = (Dictionary)jsonResult["reviews"]; string res = x["mySecondLevelReviews"].ToString();

          The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.

          M Offline
          M Offline
          michael_jhons
          wrote on last edited by
          #4

          thank you Abhinav for your help, i did apply what you've suggested withoout any luck, i just want to highlight that jsonResult["reviews"].GetType()= Arraylist what should i set the the type of keys and values in Dictionary Dictionary ? thank you again for your concern

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups