admin管理员组文章数量:1356914
I have some jQuery code which retrieves content using getJSON(). There are n JSON files, which are retrieved from the server as needed:
/json-content/data0.json
/json-content/data1.json
/json-content/data2.json
etc...
Instead, I want to store all the JSON in a single file to reduce the number of HTTP requests needed to retrieve the data.
What is the best way to bine the JSON files into one? If I concatenate the JSON files together, it no longer works with getJSON().
UPDATE - clarified my question
I have some jQuery code which retrieves content using getJSON(). There are n JSON files, which are retrieved from the server as needed:
/json-content/data0.json
/json-content/data1.json
/json-content/data2.json
etc...
Instead, I want to store all the JSON in a single file to reduce the number of HTTP requests needed to retrieve the data.
What is the best way to bine the JSON files into one? If I concatenate the JSON files together, it no longer works with getJSON().
UPDATE - clarified my question
Share Improve this question edited Apr 26, 2010 at 21:33 frankadelic asked Apr 26, 2010 at 20:49 frankadelicfrankadelic 20.8k37 gold badges114 silver badges167 bronze badges2 Answers
Reset to default 4Either as individual attributes or as an array
{
"data1":{stuff for data1},
"data2":{stuff for data2},
"data3":{stuff for data3}
}
or
{"response":[
{stuff for data1},
{stuff for data2},
{stuff for data3}]}
If you really want to reduce the number of HTTP requests from the client, one possible way is like this:
- Build a server side proxy that get JSon files from the third party data sources
- Merge your 3 JSon files in one single JSon file
- Make a single $.getJSON() call to your single JSon from client
To merge Json files, look at this post.
本文标签: javascriptCombine multiple JSON files into one retrieve using jQuerygetJSON()Stack Overflow
版权声明:本文标题:javascript - Combine multiple JSON files into one; retrieve using jQuerygetJSON() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743946225a2566455.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论