3

I am creating a javascript object from a c# object and one of the properties is a reference to a js function , but when serializing the object the value has quotes around it witch makes it a normal string and not a function. this is the current output :

{ "x": "functionNameToBeCalled" }

But I need it to be like

 { "x": functionNameToBeCalled }

Is there anyway to do this with Json.Net or do I have to create the js object manually?

I tried using the JsonPropertyAttribute but can't figure out which property to set!!!

dbc
  • 104,963
  • 20
  • 228
  • 340
Exlord
  • 5,009
  • 4
  • 31
  • 51
  • Manually create a your own serialization method. – Masoud Andalibi Sep 02 '17 at 07:56
  • 1
    Since you are using Json.NET this would appear to be a duplicate of [How to serialize a raw json field?](https://stackoverflow.com/q/15661529/3744182). Put `[JsonConverter(typeof(PlainJsonStringConverter))]` on the property whose value should be serialized as a raw, unquoted string. – dbc Sep 02 '17 at 08:22

1 Answers1

2

change the way of calling your method, something like this:

window.z= function(){ console.log('hi');}
var b = { a: 'z'}
window[b.a]();

so no need to change json serialization behavior.

hvojdani
  • 460
  • 3
  • 13