如何将JSON文件添加到我的项目 [英] How to add JSON files to my project

查看:202
本文介绍了如何将JSON文件添加到我的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个twitter客户端程序.他们给了JSON文件以包含在我的项目中. 但是我对如何将它们添加到我的项目中感到困惑. JSON文件实际上是做什么的?

I am writing a twitter client program. They have given JSON files to include in my project. But I am confused with how to add them into my project. And actually what the JSON files do ?

推荐答案

JSON是Javascript对象表示法.它是javascript对象的序列化形式. Javascript可以原生评估JSON代码,因此您需要以某种方式评估该代码.取决于文件的设置方式以及是否要将其与主要的JavaScript代码分开.

JSON is Javascript Object Notation. It is a serialized form of a javascript object. Javascript can natively eval JSON code, so you need to eval that code somehow. It kind of depends how the files are setup and whether you want to keep the separate from your main javascript code.

一个简单的事情是创建一个AJAX调用,该调用将下载文件,然后以这种方式进行评估.您可以做的其他事情是将代码作为字符串复制到主javascript中,并评估该字符串.如果文件设置正确或想要对其进行修改,则可以直接将文件中的代码评估为可以使用的全局对象.

One easy thing to do is create an AJAX call that downloads the file and then eval it that way. Something else you can do is copy the code into your main javascript as a string and eval that string. If the file is setup correctly, or you want to modify it, you can eval the code directly in the file into a global object you can then use.

希望有帮助.

这篇关于如何将JSON文件添加到我的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆