2014년 12월 11일 목요일

AI2: JSON decode problem.


I have problem with decode JSON response  from PHP serwer.

result in JSON: {"id":"1234", "id2":"567890"}

I'm using AI2 and such program:

label1 is loaded the correct text of JSON responce: {"id":"1234", "id2":"567890"}

but I got an error: 


But this works perfect:
Why?
What am I doing wrong?


--
This will be easier to debug if you right-click-Doit on all the intermediate blocks, to see how
the data looks at each step of the way.
You might need to drop values into global variable to catch them for DoIt. 
Could you post the screen shots with the DoIt results?

--
I forgot write that i'm using Android 2.3.7
I checked it on other smartfon with Android 4.0.3 and there everything works fine.

I will try to what you wrote.

--
You have to add a global variable, call it ResponseTemp, to capture the response
temporary value for your DoIt.  The local variables inside a response handler lose

their values when the event handler ends, long before you get to do your rightclick-doit.

This is extra work, but it's the only way to post-mortem your data flow.



The sequence is:

Response handler block

set global Responsetemp = response
process Responsetemp value
end

I've attached a couple of screen shots from my library of json experiments,
unfortunately without the global variable trick.



--
I did it earlier:


Result the same - Android 2.3.7 not working (the same error), 4.0.3 works fine.

I saw your answer here: [JSON] How to form JSON ?

--
So where's the screen shot with the DoIt values of the two global variables?

--
For Android 2.3.7 (not working):
and for 4.0.03 (works OK):


So, it seems to be Inventor problem. :(

--
I don't see any way this can't be a bug in AI2.  Any developers out there?

--
I checked how many characters the text is received from:responceContent
using lenhgt block, and surprise: 28

Why, if the response from the server has a length of 27 characters?

{"id":"1234", "id2":"5678"}


responceContent is returning additional character at the beginning.

So, this works on both version of Android:


But why? :)

--
Good idea to check the lengths.

If you want to shuck garbage off the front, write a short return-value procedure to locate and return just the part you want for that finicky JSON decode function.

Why do different versions of Android get or don't get an extra byte in front?

Maybe it's some kind  of character code marker?
Look for a difference between your two devices in the area of character code settings.

Check that mysterious leading character against " " to see if it's just a blank, or something else.
There might be a Web block to transform it into something more readable, like %20.

--


댓글 없음:

댓글 쓰기