I am trying to mock up some test data to check wether a json string deserializes into an object correctly.
I have some json data which is 660 lines long, so i have only included a portion
{
"DataA": "string",
"DataB": "datetime",
"DataC": {
"DataC1": "datetime",
"DataC2": "datetime",
"DataC3": "datetime",
"DataC4": int,
"DataC5": int,
"DataC6": "string",
"DataC7": int,
"DataC8": "object"
},
"DataD": {
"DataD1": decimal,
"DataD2": decimal,
"DataD3": "string",
"DataD4": int,
"DataD5": decimal,
"DataD6": "string",
"DataD7": {
"DataD7i": null,
"DataD7ii": [
I have created the corresponding classes, but am currently attempting to test them. However I am unable to get this json data into a string, as the double quotation marks close off the string. I have tried using ecsapes aswell but to no avail.
string testjson = "{
"DataA": "string",
"DataB": "datetime",
"DataC": {
"DataC1": "datetime",
"DataC2": "datetime",
"DataC3": "datetime",
"DataC4": int,
"DataC5": int,
"DataC6": "string",
"DataC7": int,
"DataC8": "object"
},
"DataD": {
"DataD1": decimal,
"DataD2": decimal,
"DataD3": "string",
"DataD4": int,
"DataD5": decimal,
"DataD6": "string",
"DataD7": {
"DataD7i": null,
"DataD7ii": ["
I want to call
ObjectA objectblah= JsonConvert.DeserializeObject<ObjectA>(output);
But cannot manage to get the json into a string. I am aware this is a trivial issue, but I am new and am stuck on this issue. any help would be greatly appreciated.
Thanks
Users can also Convert JSON File to Text by uploading the file. Download converted file with txt extension. JSON to Text Online works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.
If you need to convert a file containing Json text to a readable format, you need to convert that to an Object and implement toString() method(assuming converting to Java object) to print or write to another file in a much readabe format. You can use any Json API for this, for example Jackson JSON API.
There are two ways of converting JSON to string in Python; one way is to use json method dumps(), and another way is to use an API such as requests module in Python.
In my unit test projects, whenever I have "mass" text, I put that content into a separate text file. Then you have two choices:
Keeping it in a separate file makes editing/maintenance a lot easier.
Part of the issue looks to be the use of double quotes which can be escaped with a backslash \
, however to have a multi-line string in C#, you also need to append an @
symbol at the start like shown in this answer https://stackoverflow.com/a/1100265/2603735
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With