Is there a max length for a mapping or can jsonDecode only handle so large of a response?
Here is the Debug I printed:
WCCOAui1:["Last 24 hours"]
WCCOAui1:[dyn_errClass 0 items
WCCOAui1:]
WCCOAui1:["Array length decoded by jsonDecode: 100"]
WCCOAui1:["Total events received from Datonis: 752"]
WCCOAui1:["Total length of received string in OA: 102686"]
So I’m getting 752 events, but OA is only decoding 100 of them. I thought that maybe the receive data string couldn’t hold all the data, but the string length is correct(I matched it with a response from Postman.) The only other things I can guess are limitations of the mapping datatype, or an error in the jsonDecode function. Does anyone know of this, or a way to fix it?
Here is the code in question:
string receiveData;
mapping tags;
netPost("https://api.datonis.io/api/v3/datonis_q ... ccess-Key="+ accessKey + "&thing_key=" + thingKey+ "&from=" + fromTime + "&to=" + sCurrentTime + "&time_zone=America/Chicago", makeMapping("content", ""), receiveData);
tags = jsonDecode(receiveData);
DebugN(getLastError());
TABLE1.deleteAllLines();
DebugN("Array length decoded by jsonDecode: " + dynlen(tags[thingKey]["event_data"]));
DebugN("Total events received from Datonis: " + tags[thingKey]["total_event_count"]);
DebugN("Total length of received string in OA: " + strlen(receiveData));
for (i=1; i
JsonDecode Problem
- mkoller
- Posts:741
- Joined: Fri Sep 17, 2010 9:03 am
Re: JsonDecode Problem
There is no limit in a mapping, except memory.
Is it possible that you just do not receive all expected events ?
Like: is tells you how many are there in total (total_event_count) but what you receive is just
those within given time span (from, to), or the web service just cuts the number sent to 100
and you need to do another request to receive the rest ?
I don't see any other problem here, since it seems to be a valid JSON string, else you would get an error
when decoding and no result mapping at all.
Check the received string manually
Is it possible that you just do not receive all expected events ?
Like: is tells you how many are there in total (total_event_count) but what you receive is just
those within given time span (from, to), or the web service just cuts the number sent to 100
and you need to do another request to receive the rest ?
I don't see any other problem here, since it seems to be a valid JSON string, else you would get an error
when decoding and no result mapping at all.
Check the received string manually
- MattPaulissen
- Posts:26
- Joined: Fri Feb 19, 2016 9:27 pm
Re: JsonDecode Problem
No, it's actually giving me the full response with all the events. I have verified this with postman. I know the return string has all the data because I compared it to postman as well. It's losing it at the jsonDecode or the mapping. It is reproducible every time with different queries to different things etc. It always stops at 100 array elements.
- agruber
- Posts:147
- Joined: Tue Sep 07, 2010 2:52 pm
Re: JsonDecode Problem
I see in your example that the result variable is of type string. Seeing the documentation it needs to be a mapping. Within the mapping is a value with key name "content". I think that is the reason. Please verify.
If this does not solve the issue, you could export the result string before any processing with fputs (see documentation for example) and verify the content.
If the content is fine, the file helps having a reproducible example which you can send to your common WinCC OA support.
If this does not solve the issue, you could export the result string before any processing with fputs (see documentation for example) and verify the content.
If the content is fine, the file helps having a reproducible example which you can send to your common WinCC OA support.