Git Product home page Git Product logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on April 28, 2024
Quite right.  Fixed.

I'm not sure quite what you mean by reading a file.
Javascript does not expose file system bindings.
I could try including an example using common libraries XmlHttpRequest wrappers 
to
fetch a file from the web.

Original comment by [email protected] on 23 Sep 2009 at 5:56

  • Changed state: Accepted

from json-sans-eval.

GoogleCodeExporter avatar GoogleCodeExporter commented on April 28, 2024
I guess what I meant was to show folks how javascript might read in the JSON 
string
from an external file into your 'myJson' string, so you can manipulate it 
through
your jsonParse function, instead of just assuming the user has access to the 
string
data to begin with.

At our company, we developed an excellent function that reads individual Json
elements from an external file source, but it doesn't use your jsonParse 
function.  

Here's how we do it.  Assuming you control the remote json file to begin with, 
then
you can cause the json data on that remote page to be written surrounded by a
javascript function, so that it appears on the page like this:

   MyJsonData({ "x": "Hello, World!", "y": [1, 2, 3] });

Then, on the internal page where you need to 'read' the remote json data, you 
can put
the following javascript code:

   var headerID = document.getElementsByTagName("head")[0];         
   var InScript = document.createElement('script');
   InScript.type = 'text/javascript';
   InScript.src = "path to your remote json file";
   headerID.appendChild(InScript);

   function MyJsonData(data)
   {
    var ret_x = data.x;
   }

When the json page is loaded into the current page's header, it's MyJsonData() 
data
contents become readable by the MyJsonData(data) function on this page, and the
individual json elements can then be accessed as data.x, data.y, etc.  

What I'd like to see is how your jsonParse might be integrated within a similar
'read' function, so that the entire string can be read into your myJson 
variable from
an external json-formatted file, and then parsed using your jsonParse function.

Excellent work on your code though!

Original comment by [email protected] on 23 Sep 2009 at 6:22

from json-sans-eval.

GoogleCodeExporter avatar GoogleCodeExporter commented on April 28, 2024
Ok, so you used the word file to mean chunk of data, not a physical file on 
storage
media.

Is the scheme you're describing similar to JSONP :
http://en.wikipedia.org/wiki/JSON#JSONP ?

Original comment by [email protected] on 23 Sep 2009 at 7:55

from json-sans-eval.

GoogleCodeExporter avatar GoogleCodeExporter commented on April 28, 2024
{'key':'abcd\r\nefghigklmnop\nqrstuvwxyz'}

How to do?

Original comment by [email protected] on 28 Dec 2009 at 6:22

from json-sans-eval.

GoogleCodeExporter avatar GoogleCodeExporter commented on April 28, 2024
That is not valid JSON.  JSON only allows double quotes.

From htto://json.org/ :
  string
    ""
    " chars "

Original comment by [email protected] on 28 Dec 2009 at 7:08

from json-sans-eval.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.