Reputation: 21
i really needs all the helps available now.
Objective: How to read Json Data in normal text file putting the specific text into String variable? Coding platform: visual studio 2010 Language: C#
below is the example json data in my normal text file
{
"created_at":"Sun May 05 14:12:21 +0000 2013",
"id":331048726577692674,
"id_str":"331048726577692674",
"text":"Why play Luiz at CB?",
"user":
{
"id":458765935,
"id_str":"458765935",
"name":"Amrit Singhpong",
"screen_name":"AmritTheBlue",
"location":"Stamford Bridge",
"url":null,
"description":"17. Chelsea fan! XO Care Free",
}
}
Right now all i can do is to only read all the lines in the text file and place it into the array i created to store each and every lines. So supposing this whole example of json data is stored in a single array, my next problem would be, How do i take out the "text":"Why play Luiz at CB?" and place it into a normal string variable?
Upvotes: 1
Views: 4077
Reputation: 1172
You can use .NET JavaScriptSerializer();
{ "created_at" : "Sun May 05 14:12:21 +0000 2013",
"id" : 331048726577692674,
"id_str" : "331048726577692674",
"text" : "Why play Luiz at CB?",
"user" : { "description" : "17. Chelsea fan! XO Care Free",
"id" : 458765935,
"id_str" : "458765935",
"location" : "Stamford Bridge",
"name" : "Amrit Singhpong",
"screen_name" : "AmritTheBlue",
"url" : null
}
}
string JSON = File.ReadAllText("JSON.txt");
var serializer = new JavaScriptSerializer();
object str = serializer.DeserializeObject(JSON);
Upvotes: 4
Reputation: 34285
Your options:
JavaScriptSerializer
(in the framework)Upvotes: 1