如何在js中使用序列化的JSON对象

时间:2015-06-28 19:54:29

标签: javascript html json multiple-files

我已经将java中的对象序列化为文件中的json对象,现在我想使用它的数据。但我不知道如何获取仅包含我的JSON对象的文件。我想把它变成一个我可以在脚本中使用的js对象。

1 个答案:

答案 0 :(得分:1)

在回答here后,您可以使用jQuerygetJSON方法。

$.getJSON("/path/to/my/json_file.json", function (json) {
    imaginaryFunctionThatDoesMagicStuff(json);
});

或者,如果您可以通过其他方式获取文件,则可以使用javascript parse function

JSON.parse(raw);

根据建议here

示例:



$.getJSON("http://json-stat.org/samples/order.json",function(data)
{
  document.write(data.order.label);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
&#13;
&#13;

相关问题