If you send plain Json formatted un-serialized text from a web api and have it be de-serialized in a C# function using the jsonConvert.DeserializeObject functional? I have a co-worker who created a web api in the cloud and he sends plain text formatted to look like un-serialized Json which I try to use C# functionality to Deserialize but when I try to convert what is sent into Model classes it fails. I am telling him that the C# JsonConvert.SerializeObject must be used or it won't work. Can someone help clarify this with me?
-
All JSON is serialized by definition, as JSON is a way to serialize data. – RemcoGerlich Mar 13 '19 at 21:22
-
"unserialized JSON' is not a thing. Please provide examples of what you are talking about. – Mar 13 '19 at 21:23
-
This is what is being sent: { [ \"accesspoint\" : { \"api\" : \"test\"} ] } – holdorfs Mar 13 '19 at 22:20
1 Answers
Your colleague is right. JSON strings need to be de-serialized to turn them into objects.
Moreover, the things you call "plain text formatted to look like JSON" are JSON strings. JSON is plain text (in UTF8, with syntax rules).
Let's say you have some data structure in your program that you want to send over the network. The network can only send series of bytes, so whatever your structure was, you need to turn it into that -- you need to serialize it. JSON is one way of doing that, e.g.
'{"example": "some data"}'
is a string containing JSON. It is serialized, it's just a string of bytes to send over the network.
On the receiving end, you need to deserialize it back into some data structure, some type of hash map or dictionary or whatever it's called in C# probably.
If what you try "fails", you could ask a much more specific question showing what you tried with what data and how exactly it failed.

- 30,470
- 6
- 61
- 79
-
This is what is being sent: { [ \"accesspoint\" : { \"api\" : \"test\"} ] } – holdorfs Mar 13 '19 at 21:57
-
@holdorfs Click the edit button right under your question, and add your JSON to the question. Your question should contain everything needed to answer it. – Mar 13 '19 at 22:14
-
@holdorfs: I suspect those backslashes are not literally being sent, but are rather an artifact of how you're printing the string. – RemcoGerlich Mar 13 '19 at 22:28
-
Yes the backslashes are being sent. What should it look like being sent from jNode from AWS API? – holdorfs Mar 13 '19 at 22:33
-
Well then that is wrong, yes. JSON doesn't allow backslashes there. But it seems unrelated to serialization. – RemcoGerlich Mar 13 '19 at 22:34
-
-
In the debugger before de-serialization just like shown above. Sending it through the api doesn't change the look of the data. It still had the backslashes just like when it was sent. How should I format the Json at jNode level? What should the initial text look like? – holdorfs Mar 14 '19 at 01:45
-
Your debugger is escaping the quotes. The string is fine. See [this](https://stackoverflow.com/questions/18759324/can-the-visual-studio-debugger-display-strings-unquoted-unescaped) and [this](https://stackoverflow.com/questions/20312974/newtonsoft-json-serializeobject-without-escape-backslashes) – Mar 14 '19 at 04:48