本文介绍了动态更新的PhoneGap JSON(机器人)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

注:我的问题可能有点混乱。我会尽量解释清楚,但如果你觉得缺了点什么,请让我知道了意见。

我使用PhoneGap的创建Android应用程序。我的应用程序使用了一些数据被送入使用JSON的应用程序。我打算出货我的应用程序使用JSON它看起来像:

I am creating an Android app using phonegap. My app uses some data which is fed into the app using JSON. I plan to ship my app with a JSON which looks something like:

{
"8": [ {"subject":"Sample","room":"L2"} ],
"9": [ {"subject":"something","room":"L3"} ]
}

问题我现在面临

随着时间的推移,JSON的值可能不得不被改变。例如,样本可能需要更改为你好
这些变更必须由我从云的。这样,当用户连接到互联网,他们preSS的更新按钮,这些变化在JSON存储在其设备应该发生。

As time passes, the values of JSON may have to be changed. For example, "Sample" may need to be changed to "hello".These changes have to be made by me from the cloud. So that, when the users are connected to the internet and they press the "update" button, these changes in the JSON stored in their device should take place.

请注意:**我已经设置了托管和我的应用程序可以在域www.example.com/world.json访问更新后的JSON **

Note: **I have already set up hosting and my app can access the updated json at a domain www.example.com/world.json **

我如何可以复制world.json的内容,并把它们放到本地JSON这是我的用户的设备present?
任何帮助吗?
谢谢你。

How can I copy the contents of world.json and put them into the native JSON which is present in my user's device?Any help?Thanks.

推荐答案

您可以使用jQuery做一个远程Ajax调用,获得最新的JSON,取代现有的。
我假设你存储的localStorage现有的JSON

You can use jQuery to make a remote ajax call, get the latest JSON, replace the existing one.I am assuming that you are storing the existing JSON in localStorage

所以,你将有一个用于设置localStorage的价值,只要你想一号跑什么逻辑

So, you will have a logic that sets that localStorage value as what you want on the 1st run

if(firstRun){
    myjson={
           "8": [ {"subject":"Sample","room":"L2"} ],
           "9": [ {"subject":"something","room":"L3"} ]
    }
    window.localStorage("json", JSON.stringify(myjson));

然后在更新按钮,或从用户的某些其他事件的点击,就可以得到新的JSON和替换localStorage来现有

Then on click of update button or some other event from user, you can get the new JSON and replace the existing one in localStorage

function onclick(){
    $.post( "www.example.com/world.json", function( data ) {
        window.localStorage("json", JSON.stringify(data));
    });
}

和在任何你想使用JSON,

And where ever you want to use that JSON,

var myjson=JSON.parse(window.localStorage("json"))

我觉得这是你在找什么。

I think this is what you are looking for.

这篇关于动态更新的PhoneGap JSON(机器人)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:41