admin管理员组

文章数量:1429399

I got a very simple txt file in JSON format:

{
  "menu": "File1",
  "bday": [
      {
          "name": "teo",
          "date":"22"
      },
      {
          "name": "john",
          "date": "9"
      },
      {
          "name": "maria",
          "date": "15"
      }
   ]
}

All I want is to just fetch the data and print them. Like:

teo : 22
john:9

...etc...

I don't care about this. I just want to fetch the data.

I got a very simple txt file in JSON format:

{
  "menu": "File1",
  "bday": [
      {
          "name": "teo",
          "date":"22"
      },
      {
          "name": "john",
          "date": "9"
      },
      {
          "name": "maria",
          "date": "15"
      }
   ]
}

All I want is to just fetch the data and print them. Like:

teo : 22
john:9

...etc...

I don't care about this. I just want to fetch the data.

Share Improve this question edited Oct 11, 2012 at 17:42 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Jan 29, 2011 at 1:29 t0st0s 1,2195 gold badges19 silver badges28 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Your answer is plainly XMLHttpRequest, which is multi-browser patible JavaScript without need for a library. You can always create your own library for some backward-patibility.

Put the JSON in a file on your server (for example, data.js) and then use jQuery to fetch the file. Something like this:

var json;
$.getJSON("data.js", function(data){
    json = data;
});

本文标签: javascriptFetch JSON data from a fileStack Overflow