The way I do this in in onReceive1 and onReceive2, I do
if(responseCode!=200) { Bg.exit(responseCode);}
And in onReceive2, do
Bg.exit([res1,res2]);
if there isn't an error
then in onBackgroundData(data)
if(data instanceof Number) {//got an error}
else {//got good data}
if there was an error, you'll likely see null for data when onReceive1 and onReceive2 is called
Thanks jim_m_58... I try to explain me a little better.
I get the data correctly like you described Bg.exit([res1, res2]);
The problem is that res1 and res2 are two separate json objects. How do I save them like one (concatenate them) or similar?
(:background_method) function onBackgroundData(data) { var pendingWebRequests = getPendingWebRequest(); var type = data.keys()[0]; // Type of received data. var storedData = getProperty(type); var receivedData = data[type]; // The actual data received: strip away type key. var data1 = receivedData[0]; // res1 as JSON object var data2 = receivedData[1]; // res2 as JSON object storedData = HOW TO PUT BOTH JSON OBJECTS HERE; pendingWebRequests.remove(type); setProperty("PendingWebRequests", pendingWebRequests); setProperty(type, storedData); Ui.requestUpdate(); }
HOW TO PUT BOTH JSON OBJECTS HERE - how to store both? ^
Technically, data1
and data2
are Monkey C dictionaries which (recursively) contain dictionaries, arrays, numerical types and booleans. (They were JSON objects in the network response, but makeWebRequest() converted them into the corresponding Monkey C types.)
You can't really concatenate dictionaries (or JSON objects for that matter), but you can put 2 dictionaries in an array (as they already are in your code) and store the array.
e.g.
storedData = receivedData;
However, it looks like you want a solution where you're storing a dictionary. You can achieve that by creating a new dictionary with data1 and data2 as values.
storedData = {
:data1 => data1,
:data2 => data2
};
In this example, :data1 and :data2 can be replaced with the symbols of your choice.