|
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
|
|
|
|
|
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"];<br />
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.
|
|
|
|
|
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<tkey,tvalue> ?
thank you again for your concern
|
|
|
|
|
Since your data seems to be in JSON format, you might want to use JsonReaderWriterFactory[^] class. It will become much easier to parse.
|
|
|
|
|
I have a table that would be read into the dataset using dataadapter.fill method. The table will be of the below format
Name | Age | Score | Gender
Ram 14 75 M
Sam 15 85 M
John 16 95 M
I have an object of the following sort in c#
public class students
{
//initializing private variables
public string Name
{
//get/set
}
public string Age
{
//get/set
}
public string Score
{
//get/set
}
}
How can i convert this table in the dataset to an array of Students object?
Jack Sparrow
--------------------------------------
Defeat is not the worst of failures. Not to have tried is the true failure.
|
|
|
|
|
There are many ways. You might encapsulate Data objects within your classes, and maybe getting a IEnumerable<Student> could be a better approach:
public class Student
{
DataRow dr;
internal Student(DataRow dr)
{
this.dr = dr;
}
public string Name
{
get { return dr["Name"].ToString(); }
set { dr["Name"] = value; }
}
public string Age
{
get { return dr["Age"].ToString(); }
set { dr["Age"] = value; }
}
public string Score
{
get { return dr["Score"].ToString(); }
set { dr["Score"] = value; }
}
}
public class StudentCollection
{
public IEnumerable<Student> GetStudents()
{
foreach (DataRow dr in dt.Rows)
yield return new Student(dr);
}
}
modified on Wednesday, December 15, 2010 11:35 AM
|
|
|
|
|
If you want the data in an array of some class why bother reading it into a DataTable? That just wastes cycles.
Cut out the middleman; use a DataReader to populate your array.
|
|
|
|
|
Hi
I want to filter a bound grid through binding source filter property.
but i couldn't write a filter like this "DocumentID != 1";
it throws an exception saying ! not acceptable.
how can i achive this
|
|
|
|
|
The MSDN page on BindingSource.Filter refers to DataColumn.Expression which shows some operators inluding AND, OR, NOT.
And in SQL there isn't a != operator, however there is a basic-like <> operator.
At least one of those approaches should do it for you.
|
|
|
|
|
hi luc,
thanks for replay
i do read the full page in MSDN before posting here
what i want to do is the following
i have a list of type int named execludedFields which holds the codes for unwanted records
i want to loop through the collection to build a filter like this
"FieldCode != 1 OR FieldCode != 5 .... and so on"
i couldn't figure out how to do it because there is no negative operator
of course i can do it the other way around by getting a list called watntedFields but that requires a lot coding more than
using the execludedFields approach
so I'm asking if there is a way to build a filter that do that using the Filter property
|
|
|
|
|
1. I already told you what I know about the subject.
2.
why bother?
Hussam Fattahi wrote: FieldCode != 1 OR FieldCode != 5
is always true!
PS: and then there are parentheses, handy when the default operator precedence is not what you want, e.g. with a NOT operator.
|
|
|
|
|
sorry, my Bad
i meant AND
by using NOT do you mean i can write it like this
NOT( FieldCode = 1 AND FieldCode = 5 ....)
or like this NOT( FieldCode IN(1,5,...))
thanks again
|
|
|
|
|
I don't know. Try it, or search for documentation or examples.
|
|
|
|
|
hi
i try to inport csv file to my database in my C# winform program.
for example the csv file:
code ,name ,price
101010,computer,200$
and i done this:
char[] BI = { ',' };
string[] WI = TEMP.Split(BI);
A = WI[0].Trim().ToString();
B = WI[1].Trim().ToString();
C = WI[2].Trim().ToString();
but what i can do if the name contain (,) ?
for example
code ,name ,price
101010,computer 12,200.00,200$
if i get this type of csv:
code ,name ,price
"101010","computer 12,200.00","200$"
how to deal with this ?
|
|
|
|
|
Perhaps this link[^] will help you.
|
|
|
|
|
Thank you.
|
|
|
|
|
10!
|
|
|
|
|
Well done!
You should be seeing a small spike in your reputation score today...
Will Rogers never met me.
|
|
|
|
|
Recently I have seen this thread[^] which will help you.
thatraja |Chennai|India|
Brainbench certifications Univotes are like kid's kisses don't reject it Do what you want quickly because the Doomsday on 2012 My childhood story
|
|
|
|
|
goldsoft wrote: code ,name ,price
"101010","computer 12,200.00","200$"
For this there's a solution, You can use regex to use. follow the step
1. Replace the ',' Char inside "abc,xyz" with some Character not conflicted with CSV delimeter, Say @, using Regex.
2. Now you will get exact split in three words, Once splitted further Replace the '@' with ',' in Splitted string.
goldsoft wrote: code ,name ,price
101010,computer 12,200.00,200$
if i get this type of csv:
For this I don't think of any Intelligent detection.
|
|
|
|
|
Why not treat the csv as a db. You could use Jet OleDb, or odbc.
Details here.
I used to think....
Finally I realized it's no good.
|
|
|
|
|
Yeah, what they said, especially Rive .
goldsoft wrote: WI[0].Trim().ToString();
You don't need the ToString.
|
|
|
|
|
Could be a deja vu, but I think I have seen this question in random forums (or a very similar one) every two weeks in the last months. Please, write csv in the search text box at the top of this forum. Maybe you'll get what you need.
|
|
|
|
|
|
This is not a right place to post your article Ad.
|
|
|
|