jQuery getJSON()方法

I have a JSON file in folder App_Data . Now I want to read this file and keep it in a JS variable. This is the code I wrote but it's not working.

$(document).ready(function () {
  $.getJSON("~/App_Data/smartParkTotalJson.json", function(json) {
  });
});

UPDATE

For now, I just want to check if its read. so I wrote this code:

        <script>
        $(document).ready(function () {
            $.getJSON("/App_Data/smartParkTotalJson.json", function (json) {
                alert("sff");
            });
        });
    </script>

I want to get some alert

The ~ character is only valid within ASP.Net routing constructs. JS will not translate it to a valid URL. To fix this you need to either use a relative path from the root of the site:

$.getJSON("/App_Data/smartParkTotalJson.json", function(json) {

Or interpolate Razor in to your code - assuming this JS code is inside an MVC View:

$.getJSON('@Url.Context("~/App_Data/smartParkTotalJson.json")', function (json) {

Also note that the App_Data folder is configured by default to not respond to HTTP requests. It is intended to hold app-specific information. I'd suggest creating your own folder to host this file.