Reputation: 2282
I am trying to remove the quotes from a particular member value from the JSON.
I need the JSON to be:
"editor": TextAreaEditor
Not:
"editor": "TextAreaEditor"
I need to be able to deserialize JSON into an object and serialize back to JSON
I am basically deserializng the below JSON and then serializing back into JSON for my c# web api.
configList = JsonConvert.DeserializeObject<List<ReportJsonDetails>>(json, settings);
I get this
Unexpected character encountered while parsing value: T. Path
'[0].headers[2].editor'
I saw a bunch of examples using JsonConverter. But most of the examples are manipulating the values and I doesnt seem like booleans, nulls and numbers are implemented that way.
JSON
[ {
"name": "DataviewReport",
"headers": [
{
"id": "id",
"caption": "Id",
"dataField": "id",
"visible": false
},
{
"id": "lastname",
"caption": "Last Name",
"dataField": "lastname",
"visible": true
},
{
"id": "FirstName",
"caption": "First Name",
"dataField": "levelNum",
"visible": true,
"editor": TextAreaEditor
}
] } ]
Upvotes: 2
Views: 100
Reputation: 156624
{
"id": "FirstName",
"caption": "First Name",
"dataField": "levelNum",
"visible": true,
"editor": TextAreaEditor
}
When you see this representation in something like your development tools, this isn't JSON. This is a JSON-like representation of the memory model of the JavaScript environment. TextAreaEditor
is a concept that exists in that JavaScript environment, which doesn't translate universally to other environments.
JSON is meant to be a serialization language that translates well into JavaScript, but it's not the same as the JavaScript object model itself. If you have JavaScript objects containing values that aren't inherently serializable, then they cannot be included in JSON and retain the same meaning.
So there isn't (and shouldn't be) a way to force C# to deserialize the value you're giving it, because it's not valid JSON. The solution to your problem is to re-think what data you actually need to transfer from your client to your server, and create a translation layer between that data model and the one your client is using directly: a so-called Data Transfer Object. Then serialize that.
Upvotes: 1