Page 1 of 1
Receive Php Associative Arrays : HTTPRequest / ExamineJSON
Posted: Thu Sep 04, 2014 8:18 pm
by falsam

Script Php
Code: Select all
<?php
$array = array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
echo json_encode($array);
?>

Code SpiderBasic
Code: Select all
Enumeration
#Json
EndEnumeration
Procedure HttpGetEvent(Success, Result$)
Protected i
If Success
Debug Result$
If ParseJSON(#Json, Result$)
ObjectValue = JSONValue(#Json)
If ExamineJSONMembers(ObjectValue)
While NextJSONMember(ObjectValue)
Debug JSONMemberKey(ObjectValue) + " = " + GetJSONInteger(JSONMemberValue(ObjectValue))
Wend
EndIf
EndIf
Else
Debug "HTTPRequest(): Error"
EndIf
EndProcedure
HTTPRequest(#PB_HTTP_Get, "receivedata3.php", "", @HttpGetEvent())

Test:
http://s242132022.onlinehome.fr/sb-demophp3/index.html
Re: Receive Php Associative Arrays : HTTPRequest / ExamineJS
Posted: Fri Sep 05, 2014 10:57 pm
by freak
You can also get the data directly into a PB Map like this:
Code: Select all
Enumeration
#Json
EndEnumeration
Procedure HttpGetEvent(Success, Result$)
Protected i
If Success
Debug Result$
If ParseJSON(#Json, Result$)
; transfer the php array to a map
NewMap Values.l()
ExtractJSONMap(JSONValue(#Json), Values())
; display the result
ForEach Values()
Debug MapKey(Values()) + " = " + Values()
Next Values()
EndIf
Else
Debug "HTTPRequest(): Error"
EndIf
EndProcedure
HTTPRequest(#PB_HTTP_Get, "receivedata3.php", "", @HttpGetEvent())
Re: Receive Php Associative Arrays : HTTPRequest / ExamineJS
Posted: Fri Sep 05, 2014 11:08 pm
by falsam
Thank you freak. This solution is more interesting than mine.