I am using XSuperObject to create some JSON to be used in JQuery. This is an options list and for the most part it is fine. However, I am trying to get it to produce the function parameter correctly, and failing dismally. What I need is a raw string type property so that it doesn't escape quotes and doesn't surround the value with quotes either . At the moment I am adding it as a string type (ISuperObject.S['name'] := Value). It is producing

I am using XSuperObject to create some JSON to be used in JQuery. This is an options list and for the most part it is fine. However, I am trying to get it to produce the function parameter correctly, and failing dismally. What I need is a raw string type property so that it doesn't escape quotes and doesn't surround the value with quotes either . At the moment I am adding it as a string type (ISuperObject.S['name'] := Value). It is producing

"click":"function() { $(this).dialog(\"close\"); $(this).html = \"\";}"

when I need

"click":function() { $(this).dialog("close"); $(this).html = "";}

any ideas (rather than StringReplace)? Thanks

Comments

  1. Nope. The first snippet is valid json. The second is not. The first is what you need.

    ReplyDelete
  2. Hi. David Heffernan is right.
    Also you can use (") instead of ('). for example
    "click": "function(){$(this).dialog('close'); $(this).html='';}"

    ReplyDelete
  3. Onur YILDIZ​​ that's probably not going to help Russell who might go that way until he needs a double quote and then be back where he started. He really needs to get to grips with escaping. Needs to realise that escaping is purely for the benefit of the parser. The actual string is the unescaped version.

    ReplyDelete
  4. I guess that solves your problems :)
    https://github.com/onryldz/x-superobject/commit/311a3916fb0f281b4516a1027fa87ea7ad7a00b5

    eg.
    ISuperObject.Raw['name'] := 'function() { $(this).dialog("close"); $(this).html = "";}';

    output:
    {"name":function() { $(this).dialog("close"); $(this).html = "";}}

    ReplyDelete
  5. Onur YILDIZ​ the output isn't json tho.....

    ReplyDelete
  6. David Heffernan Yes, output isn't json,.But this is JavaScript Object, without notation :)

    ReplyDelete
  7. First sentence says that Russell is creating json.

    ReplyDelete
  8. I should have said pseudo JSON, I thought that the mention of JQuery was enough to imply that. Apologies if it was not clear.

    Onur YILDIZ That certainly looks like what I need :-)

    ReplyDelete
  9. Onur YILDIZ that did the trick, many thanks. That makes XSuperObject a great JQuery builder.

    ReplyDelete
  10. Makes no sense to me at all. Sorry. Can't understand what you are going to do with that text. You can't parse it since it isn't JSON. What can you do with it?

    ReplyDelete
  11. David Heffernan  feed it into a Jquery script that will run in a browser. you can't have the function inside quotes as it will just see it as a string and not something to execute. In this case the quotes would cause an exception to be thrown.

    ReplyDelete

Post a Comment