我正在编写一个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文件添加到我的项目
发布评论