-2

So I have this .json file: temp_file.json

Now all I need to do is get whatever is in this .json file, and put it in a string using C# in Visual Studio 2017.

That's it.

I don't want it to be turned into a object of a certain class or whatever. Just get whatsever in the file, right into a string.

A lot of other questions/answers I have stumbled upon are about desirializing and serializing etc. I don't need that. Just turn the .json file in to a string. No need to write it to a console or whatsoever.

Somewhy I just cant lay my finger on it. It sounds simple to do...

user7410216
  • 175
  • 1
  • 2
  • 10
  • 1
    No different to loading any file contents as a string. – Jamiec Sep 05 '17 at 14:30
  • 2
    [`File.ReadAllText()`](https://msdn.microsoft.com/en-us/library/system.io.file.readalltext%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) ? – Matthew Watson Sep 05 '17 at 14:31
  • Have a look at the File.ReadAllText method: https://msdn.microsoft.com/en-us/library/ms143368(v=vs.110).aspx – Riv Sep 05 '17 at 14:31

1 Answers1

5

You dont get any simpler than

var contents = File.ReadAllText(@"drive:\path\to\yourfile.json");
Jamiec
  • 133,658
  • 13
  • 134
  • 193
  • @Sinatr what a terrifically helpful comment. Do you want to tell me *what specifically* doesn't work? Did you get no text? Did the universe implode? Soething in between perhaps? – Jamiec Sep 05 '17 at 14:49
  • @Sinatr escape the string either by using double slash (`"C:\\path\\to...."`) or by prefixing it with `@` as per the updated answer. – Jamiec Sep 05 '17 at 14:59