Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
10
Erster Beitrag:
vor 1 Jahr, 3 Monaten
Letzter Beitrag:
vor 1 Jahr, 3 Monaten
Beteiligte Autoren:
Sammy Broeders, Allard, bosher, Peter van Vuuren, HarryW

JSON data

Startbeitrag von Sammy Broeders am 27.04.2016 14:52

Hello all,

I had a simular question before with JSON, now i have a web API to receive dutch adres information and can't exctract a JSON string with JSONTOVARIANT(). Below the json data i receive. Is there anyone with a solution? I tried a lot of things but nothing works!

{"_embedded":{"addresses":[{"city":{"id":"3594","label":"Amsterdam"},"letter":null,"id":"0363200000158443","purpose":null,"postcode":"1012NX","municipality":{"id":"0363","label":"Amsterdam"},"nen5825":{"street":"KALVERSTRAAT","postcode":"1012 NX"},"street":"Kalverstraat","number":1,"province":{"id":"27","label":"Noord-Holland"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[4.89214047794,52.3725040602]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[121286,487296]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0363200000158443/";}}}]},"_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/?postcode=1012NX&number=1";}}}

Thanks,
Sammy

Antworten:

With the code below i recieve in sAlgemeen the data as in my first post, but by Info(VAlgemeen.city.street) i recieve 0.

VAlgemeen is Variant

VAlgemeen = JSONToVariant(sAlgemeen)

Info(VAlgemeen.city.street)[/i]

von Sammy Broeders - am 28.04.2016 13:45
Nobody any experience with this?
Then i start looking for another database with dutch adresses.

von Sammy Broeders - am 29.04.2016 09:59
Hi Sammy,

What is your real problem...

I never heard about 'JSON' data but i saw it's something like XML.

Don't' you see all the data you need in the message or do you want to extract the data in a easy way ? (JSONToVariant)

von HarryW - am 29.04.2016 10:48
Hello Harry,

I want to extract the data, but with JSONToVariant() i don`t receive something.
Mayby there is another way to extract the data.

von Sammy Broeders - am 29.04.2016 10:56
Hi Sammy,

If I do a vVariant=JSONToVariant(yourstring) I get the right values in the Variant variable


sJSON is ANSI string
vVariant is Variant

sJSON = [
{"_embedded":{"addresses":[{"city":{"id":"3594","label":"Amsterdam"},"letter":null,"id":"0363200000158443","purpose":null,"postcode":"1012NX","municipality":{"id":"0363","label":"Amsterdam"},"nen5825":{"street":"KALVERSTRAAT","postcode":"1012 NX"},"street":"Kalverstraat","number":1,"province":{"id":"27","label":"Noord-Holland"},"addition":null,"geo":{"center":{"wgs84":{"crs":{"properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"},"type":"name"},"type":"Point","coordinates":[4.89214047794,52.3725040602]},"rd":{"crs":{"properties":{"name":"urn:ogc:def:crs:EPSG::28992"},"type":"name"},"type":"Point","coordinates":[121286,487296]}}},"type":"Verblijfsobject","_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/0363200000158443/";}}}]},"_links":{"self":{"href":"https://postcode-api.apiwise.nl/v2/addresses/?postcode=1012NX&number=1";}}}
]

vVariant=JSONToVariant(sJSON)

Info(vVariant._embedded.addresses[1].city.label)
Info(vVariant._embedded.addresses[1].postcode)
//...


von Peter van Vuuren - am 29.04.2016 11:44
Peter,

Thank you very much!

My fault was in the addresses[1] :-)
Now it works.

Sammy

von Sammy Broeders - am 29.04.2016 12:10
Hi
Any I deas How this works if jsontovarriant is not availeble. Iam trying to do some map stuff in php modus but in php modus the jsaontovarriant isnot availeble. The fault message states something to use like compile with ?? Anyone an Idea ?

I get the json bac via httpresult but cannot handle it ??

regards
Allard

von Allard - am 30.04.2016 10:36
Yo Allard.

This is what I use in WM

I send my URL then do something like below.

SBuf is Buffer= HTTPGetResult()


arrMyResult is array of ST_Event //ST_Event is structure defined in correct field order as incoming JSON

Deserialize(arrMyResult, SBuf, psdJSON)
ct is int = ArrayCount(arrMyResult)
sOut is string
sOut = ArrayToString(arrMyResult)

ct = 0
FOR EACH STRING sUline OF sOut SEPARATED BY CR
ct++
IF ct>2 THEN BREAK
LooperAddLine(LOOP_Events,ExtractString(sUline,3),ExtractString(sUline,4),ExtractString(sUline,5),ExtractString(sUline,1),ExtractString(sUline,7))

END

von bosher - am 11.05.2016 07:53
Hi ,

I think psdJSON is not availeble in php modus :sneg:

regards
Allard

von Allard - am 12.05.2016 21:20
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.