c#


Need to extract Dictionary from an Object of Type ArrayList [duplicate]


This question already has an answer here:
Getting access to ArrayList object
2 answers
I have a Dictionary.
It has 3 keys:kind, Id, and items.
Value of items is an Object of type ArrayList which contains a Dictionary inside.
How to extract this Dictionary which is inside the object of Type ArrayListenter image description here
Similary, that inner Dictionary has keys:kind, id, etag, selflink, volumeInfo.
Out of these, the value of volumeInfo again consist of an object of Type ArrayList which contains a Dictionary.
I need to extract values of title, subtitle, authors from the most inner Dictionary of volumeInfo
Any element in your Dictionary and ArrayList are treated as object, which means the compiler doesn't know about the actual type. To use one of these elements, you'll have to cast it:
ArrayList list = (ArrayList)dict["items"];
However, if the dictionary does not contain an "items" key, or if the value for the "items" key is not an ArrayList, this code will throw an exception. If you know the contents of your data structure are always the same, this doesn't need to be a problem.
You can test whether the dictionary contains a certain entry:
object o;
if (!dict.TryGetValue("items", out o))
{
// item not found!
}
And then test - and cast - the element:
ArrayList items = o as ArrayList;
if (items == null)
{
// items is not an ArrayList!
}
Accessing the ArrayList is similar regarding the casting bit.
Your data would be much easier to access (and simpler to code around) when you create an object that has "Kind", "TotalItems" and "Items" properties. Even if this data structure is the result of Json or Xml deserialization, there are serializers that can deserialize into dedicated classes.

Related Links

Syntax Highlighting in FlowDocumentControl for RScript
C# inserting table, error
How to IsReadOnly change in cell in datagrid in wpf using mvvm
What exception should I throw for a failed file parsing?
Visual Studio Debug and variable watching
How to pass parameters to in the DbContext.Database.ExecuteSqlCommand method to update / insert a XML node?
Preventing Renaming file extension in Telerik RadFileExplorer
Serialization of Generic Classes
Change data with buttonclick - MVVM
How to perform functions on keyboard press c#
How to add data into Specified columns in mysql using c#
WinForm RichTextBox text color changes too many characters
Line break after a line containing specific Word
Translating VB.net to C# (configuration manager issue) [closed]
Setting per request value for ServicePointManager.SecurityProtocol [duplicate]
Google Search: How to construct a reverse image search URL (take 2)

Categories

HOME
model-view-controller
optimization
leaflet
typo3
grpc
casting
aix
latex
reference
assign
app-store
xss
thermal-printer
yuv
docker-compose
procmon
restheart
unreal-engine4
ng2-charts
browsermob
dompdf
brightway
md2
glibc
summernote
descriptor
include-path
advertising
sha
ckeditor4.x
android-6.0-marshmallow
git-submodules
hierarchy
semantic-ui-react
intermec
asp.net-webhooks
gstreamer-1.0
mybatis-generator
google-chrome-console
aura-framework
jquery-ui-slider
test-kitchen
datagridviewcombobox
paperclip
amazon-rds-aurora
libzip
easyquery
standard-error
jcs
wink
richtext
liferay-ide
blitz3d
computed-properties
zsh-completion
dbi
kik
sbt-proguard
std
markerspiderfier
google-app-engine-php
cascading
skscene
producer-consumer
libgcrypt
gitk
jain-sip
pdcurses
euro
page-refresh
data-representation
backtrace
grunt-contrib-connect
dirname
parsefloat
switchpreference
dateadd
enquire.js
acrofields
kuka-krl
grape-api
caroufredsel
nokogiri
mosix
simplemembership
architectural-patterns
esi
event-propagation
erlide
motorola-droid
ruby-1.9
scsf
nbehave
meego-harmattan
mysql-logic
script-tag
cstring
paperless

Resources

Encrypt Message