Comments (5)
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.
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.
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.
{'key':'abcd\r\nefghigklmnop\nqrstuvwxyz'}
How to do?
Original comment by [email protected]
on 28 Dec 2009 at 6:22
from json-sans-eval.
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)
- objects with numeric properties are not interpreted correctly HOT 3
- how to access multiple records
- Error in Chrome
- how do you traverse the parsed json object? HOT 7
- Can't parse top-level strings HOT 5
- I want to use this file. HOT 1
- Traversing multiple json results HOT 1
- Add "try{h=h.match(s);}catch(e){return h;} " to preventing re-parse!
- question
- Conditional operator for Json Query
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-sans-eval.