1

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?

2
  • 2
    Use JSON.net to parse the JSON data: james.newtonking.com/projects/json-net.aspx you wont need to write the custom JSON parser yourself. Commented Jun 10, 2013 at 10:04
  • Looks like the data is returned by Twitter API... :) Commented Jun 10, 2013 at 10:17

2 Answers 2

4

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);

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

Your options:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.