Loading ...
Sorry, an error occurred while loading the content.

Re: [json] JSON with HTML snippet

Expand Messages
  • shalini israni
    How are you constructing the JSON object on the serverside before u send it to the client side? I feel something is mucking up there... Could u paste that
    Message 1 of 7 , Feb 14, 2007
    • 0 Attachment
      How are you constructing the JSON object on the serverside before u send it
      to the client side? I feel something is mucking up there... Could u paste
      that code??? I'm not into php...but maybe someone else on the group is... :)
      No sweat..it'll get solved!

      On 2/14/07, weilandaj <weilandaj@...> wrote:
      >
      > Hi All,
      >
      > I'm having some trouble with an element of my web application with json.
      >
      > The short story is I am sending database as part of an ajax request.
      > One piece of that data is HTML text. On the server end I'm using php
      > with smarty templates and need to send a short bit of HTML that comes
      > from a template.
      >
      > The problem is the html snippet is being severely mangled on the
      > browser end (tested in IE and FF). Here's an example:
      >
      > {"html":"<a href=\"4427-New-Gaming-Channel.html\"\>New Gaming
      > Channel</a\><b\> . 8 Views</b\>","id":"4427"}
      >
      > The HTML becomes:
      >
      > <a ew-Gaming-Channel.html">New Gaming Channel</a><b> . 8 Views</b>
      >
      > I've tried all sorts of escaping and other things. I'm really stuck
      > as to why this happens.
      >
      > Thanks for you help.
      >
      >
      >



      --

      Shalini


      [Non-text portions of this message have been removed]
    • weilandaj
      I m using the php json extension. http://us3.php.net/manual/en/function.json-encode.php It generates exactly what I pasted in my first message. After it gets
      Message 2 of 7 , Feb 14, 2007
      • 0 Attachment
        I'm using the php json extension.

        http://us3.php.net/manual/en/function.json-encode.php

        It generates exactly what I pasted in my first message. After it gets
        eval()'ed it gets mangled. I did some more testing and one thing that
        stood out is "href" seems to get yanked out for some reason in the
        eval. Not sure if that's some kind of security thing


        --- In json@yahoogroups.com, "shalini israni" <shaliny.i@...> wrote:
        >
        > How are you constructing the JSON object on the serverside before u
        send it
        > to the client side? I feel something is mucking up there... Could u
        paste
        > that code??? I'm not into php...but maybe someone else on the group
        is... :)
        > No sweat..it'll get solved!
        >
        > On 2/14/07, weilandaj <weilandaj@...> wrote:
        > >
        > > Hi All,
        > >
        > > I'm having some trouble with an element of my web application with
        json.
        > >
        > > The short story is I am sending database as part of an ajax request.
        > > One piece of that data is HTML text. On the server end I'm using php
        > > with smarty templates and need to send a short bit of HTML that comes
        > > from a template.
        > >
        > > The problem is the html snippet is being severely mangled on the
        > > browser end (tested in IE and FF). Here's an example:
        > >
        > > {"html":"<a href=\"4427-New-Gaming-Channel.html\"\>New Gaming
        > > Channel</a\><b\> . 8 Views</b\>","id":"4427"}
        > >
        > > The HTML becomes:
        > >
        > > <a ew-Gaming-Channel.html">New Gaming Channel</a><b> . 8 Views</b>
        > >
        > > I've tried all sorts of escaping and other things. I'm really stuck
        > > as to why this happens.
        > >
        > > Thanks for you help.
        > >
        > >
        > >
        >
        >
        >
        > --
        >
        > Shalini
        >
        >
        > [Non-text portions of this message have been removed]
        >
      • shalini israni
        I donno...sometimes using APIs is messy... i used a JavaAPI onec..that was great...but this one time it really messed me up bad...so i had to resort to
        Message 3 of 7 , Feb 14, 2007
        • 0 Attachment
          I donno...sometimes using APIs is messy... i used a JavaAPI onec..that was
          great...but this one time it really messed me up bad...so i had to resort to
          creating my own JSON object on the server side... pasted the code below....
          mine to was XHTML that caused the API to trip....

          This is Java code..but maybe u can look at it and write the PHP equivalent
          .....


          public JSONObject feedToJSONObject(String feedContent) {
          JSONObject json = new JSONObject(); // main json object to be
          returned
          JSONArray itemArray = new JSONArray();
          Document doc = XMLEditor.getDOMFromXMLString(feedContent);

          NodeList items = doc.getElementsByTagName("item"); // items should
          be a
          // JSONArray
          for (int i = 0; i < items.getLength(); i++) {
          NodeList children = items.item(i).getChildNodes();
          String data = "";
          for (int j = 0; j < children.getLength(); j++) { // this part
          // relies on the
          // fact that
          // title comes
          // before link
          // hence the
          // comma
          if (children.item(j).getNodeName().equalsIgnoreCase("link"))
          data += "\"link\":\"" + children.item
          (j).getFirstChild().getNodeValue()
          + "\"}";
          if (children.item
          (j).getNodeName().equalsIgnoreCase("title"))
          data += "{\"title\":\"" + children.item
          (j).getFirstChild().getNodeValue()
          + "\",";
          }
          try {
          JSONObject itemChildren = new JSONObject(data);
          itemArray.put(itemChildren);
          } catch (JSONException jEx) {
          jEx.printStackTrace();
          }
          }
          try {
          json.put("items", itemArray);
          } catch (JSONException jEx) {
          jEx.printStackTrace();
          }
          return json;

          }


          On 2/15/07, weilandaj <weilandaj@...> wrote:
          >
          > I'm using the php json extension.
          >
          > http://us3.php.net/manual/en/function.json-encode.php
          >
          > It generates exactly what I pasted in my first message. After it gets
          > eval()'ed it gets mangled. I did some more testing and one thing that
          > stood out is "href" seems to get yanked out for some reason in the
          > eval. Not sure if that's some kind of security thing
          >
          > --- In json@yahoogroups.com <json%40yahoogroups.com>, "shalini israni" <
          > shaliny.i@...> wrote:
          > >
          > > How are you constructing the JSON object on the serverside before u
          > send it
          > > to the client side? I feel something is mucking up there... Could u
          > paste
          > > that code??? I'm not into php...but maybe someone else on the group
          > is... :)
          > > No sweat..it'll get solved!
          > >
          > > On 2/14/07, weilandaj <weilandaj@...> wrote:
          > > >
          > > > Hi All,
          > > >
          > > > I'm having some trouble with an element of my web application with
          > json.
          > > >
          > > > The short story is I am sending database as part of an ajax request.
          > > > One piece of that data is HTML text. On the server end I'm using php
          > > > with smarty templates and need to send a short bit of HTML that comes
          > > > from a template.
          > > >
          > > > The problem is the html snippet is being severely mangled on the
          > > > browser end (tested in IE and FF). Here's an example:
          > > >
          > > > {"html":"<a href=\"4427-New-Gaming-Channel.html\"\>New Gaming
          > > > Channel</a\><b\> . 8 Views</b\>","id":"4427"}
          > > >
          > > > The HTML becomes:
          > > >
          > > > <a ew-Gaming-Channel.html">New Gaming Channel</a><b> . 8 Views</b>
          > > >
          > > > I've tried all sorts of escaping and other things. I'm really stuck
          > > > as to why this happens.
          > > >
          > > > Thanks for you help.
          > > >
          > > >
          > > >
          > >
          > >
          > >
          > > --
          > >
          > > Shalini
          > >
          > >
          > > [Non-text portions of this message have been removed]
          > >
          >
          >
          >



          --

          Shalini


          [Non-text portions of this message have been removed]
        • weilandaj
          I have a feeling something isn t being escaped that should be but I ve tried everything I can think of. ... onec..that was ... resort to ... below.... ...
          Message 4 of 7 , Feb 15, 2007
          • 0 Attachment
            I have a feeling something isn't being escaped that should be but I've
            tried everything I can think of.


            --- In json@yahoogroups.com, "shalini israni" <shaliny.i@...> wrote:
            >
            > I donno...sometimes using APIs is messy... i used a JavaAPI
            onec..that was
            > great...but this one time it really messed me up bad...so i had to
            resort to
            > creating my own JSON object on the server side... pasted the code
            below....
            > mine to was XHTML that caused the API to trip....
            >
            > This is Java code..but maybe u can look at it and write the PHP
            equivalent
            > .....
            >
            >
            > public JSONObject feedToJSONObject(String feedContent) {
            > JSONObject json = new JSONObject(); // main json object to be
            > returned
            > JSONArray itemArray = new JSONArray();
            > Document doc = XMLEditor.getDOMFromXMLString(feedContent);
            >
            > NodeList items = doc.getElementsByTagName("item"); // items
            should
            > be a
            > // JSONArray
            > for (int i = 0; i < items.getLength(); i++) {
            > NodeList children = items.item(i).getChildNodes();
            > String data = "";
            > for (int j = 0; j < children.getLength(); j++) { // this
            part
            > // relies on the
            > // fact that
            > // title comes
            > // before link
            > // hence the
            > // comma
            > if
            (children.item(j).getNodeName().equalsIgnoreCase("link"))
            > data += "\"link\":\"" + children.item
            > (j).getFirstChild().getNodeValue()
            > + "\"}";
            > if (children.item
            > (j).getNodeName().equalsIgnoreCase("title"))
            > data += "{\"title\":\"" + children.item
            > (j).getFirstChild().getNodeValue()
            > + "\",";
            > }
            > try {
            > JSONObject itemChildren = new JSONObject(data);
            > itemArray.put(itemChildren);
            > } catch (JSONException jEx) {
            > jEx.printStackTrace();
            > }
            > }
            > try {
            > json.put("items", itemArray);
            > } catch (JSONException jEx) {
            > jEx.printStackTrace();
            > }
            > return json;
            >
            > }
            >
            >
            > On 2/15/07, weilandaj <weilandaj@...> wrote:
            > >
            > > I'm using the php json extension.
            > >
            > > http://us3.php.net/manual/en/function.json-encode.php
            > >
            > > It generates exactly what I pasted in my first message. After it gets
            > > eval()'ed it gets mangled. I did some more testing and one thing that
            > > stood out is "href" seems to get yanked out for some reason in the
            > > eval. Not sure if that's some kind of security thing
            > >
            > > --- In json@yahoogroups.com <json%40yahoogroups.com>, "shalini
            israni" <
            > > shaliny.i@> wrote:
            > > >
            > > > How are you constructing the JSON object on the serverside before u
            > > send it
            > > > to the client side? I feel something is mucking up there... Could u
            > > paste
            > > > that code??? I'm not into php...but maybe someone else on the group
            > > is... :)
            > > > No sweat..it'll get solved!
            > > >
            > > > On 2/14/07, weilandaj <weilandaj@> wrote:
            > > > >
            > > > > Hi All,
            > > > >
            > > > > I'm having some trouble with an element of my web application with
            > > json.
            > > > >
            > > > > The short story is I am sending database as part of an ajax
            request.
            > > > > One piece of that data is HTML text. On the server end I'm
            using php
            > > > > with smarty templates and need to send a short bit of HTML
            that comes
            > > > > from a template.
            > > > >
            > > > > The problem is the html snippet is being severely mangled on the
            > > > > browser end (tested in IE and FF). Here's an example:
            > > > >
            > > > > {"html":"<a href=\"4427-New-Gaming-Channel.html\"\>New Gaming
            > > > > Channel</a\><b\> . 8 Views</b\>","id":"4427"}
            > > > >
            > > > > The HTML becomes:
            > > > >
            > > > > <a ew-Gaming-Channel.html">New Gaming Channel</a><b> . 8 Views</b>
            > > > >
            > > > > I've tried all sorts of escaping and other things. I'm really
            stuck
            > > > > as to why this happens.
            > > > >
            > > > > Thanks for you help.
            > > > >
            > > > >
            > > > >
            > > >
            > > >
            > > >
            > > > --
            > > >
            > > > Shalini
            > > >
            > > >
            > > > [Non-text portions of this message have been removed]
            > > >
            > >
            > >
            > >
            >
            >
            >
            > --
            >
            > Shalini
            >
            >
            > [Non-text portions of this message have been removed]
            >
          • xxppmmssttooss
            Hi, i want to use JSON also with HTML snippets. The snippet has included Smarty variables, i use the FCKeditor as wysiwyg-editor. Firstly i found out that the
            Message 5 of 7 , Mar 6, 2007
            • 0 Attachment
              Hi,

              i want to use JSON also with HTML snippets. The snippet has included
              Smarty variables, i use the FCKeditor as wysiwyg-editor.
              Firstly i found out that the quotation mark (") in the HTML snippet
              will destroy the JSON encoded object. I read json.org, and i read the
              control characters (",\,/ etc.) can not be unicode chars like all
              other chars. But i trying to replace the control characters in the
              json-wanted format (\",\\,\/ etc.) and it will not work :(

              But when i replace only the quotation mark (") with the HTML code
              " it will works:

              replace(/"/g, "\"""); (client)
              str_replace('"','"',$foo); (server)

              Only with this change, i can send a little bit HTML code and smarty
              variables (<b>{$foo}</b>,{if $bar}<i>{$bar}</i>{/if}).
              It will works, but not fine!!!

              Sometimes, when i send HTML snippets with this solution, it will
              works, but sometime, i can't decode the JSON object.

              Firstly i think, another character will destroy the JSON object like
              the quotation mark (") before... I can't found another character, when
              it sometimes works, and sometimes not works, with the same HTML
              snippet...

              I need also a solution for sending HTML code (or other programming
              code, css, javascript etc.) with an JSON object for my AJAX application.
            Your message has been successfully submitted and would be delivered to recipients shortly.