ImonBayazid
ImonBayazid

Reputation: 1096

saving a json file in a text file

I have a link like translate.google.com/translate_a/t?client=t&text=like&hl=en&sl=en&tl=bn&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=4&tsel=0&otf=1&ssel=4&tsel=0&sc=1.

Here in text=like it will change like text=book text=pen, which means it will be my input word, and I will loop it for 1000 times.

I'm making a dictionary. The above url outputs JSON data.

I want to loop through 1000 words and get their json output into one text file - how can I do that in c#?

Upvotes: 3

Views: 9689

Answers (2)

Christian Stewart
Christian Stewart

Reputation: 15519

You will want to query for the JSON data, and parse it using c# JSON.

This question contains extensive information about how to parse JSON.

You can download the JSON by querying that page, using WebClient ToString. You can then pass this into the JSON parser.

Depending on what you want to do with the data (you're not very clear on this), you can then use the JSON object to manipulate it.

Alternatively, if you just want to download the data to a file, you can use WebClient DownloadFile.

Upvotes: 0

user1968030
user1968030

Reputation:

see this sample maybe usfull

Person person = GetPerson();


    using (FileStream fs = File.Open(@"c:\person.json", FileMode.CreateNew))
    using (StreamWriter sw = new StreamWriter(fs))
    using (JsonWriter jw = new JsonTextWriter(sw))
    {
      jw.Formatting = Formatting.Indented;

      JsonSerializer serializer = new JsonSerializer();
      serializer.Serialize(jw, person);
    }

Upvotes: 3

Related Questions