[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Liberty-eiffel] JSON and XML parser -- newbie question
From: |
Raphael Mack |
Subject: |
Re: [Liberty-eiffel] JSON and XML parser -- newbie question |
Date: |
Thu, 14 Feb 2019 19:37:14 +0100 |
User-agent: |
Evolution 3.30.5-1 |
Hello Paul,
first a warm welcome on this list!
You are right, there are no samples in the tutorial for the JSON lib,
but we have some tests in test/lib/json.
Anyhow, basically you need an error handler:
on_error (message: ABSTRACT_STRING)
do
-- do something with the json-parse-error here
end
and a
parser: JSON_PARSER
then pass an INPUT_STREAM - which you can create as STRING_INPUT_STREAM
from a STRING - to
parser.parse_json_text
The result here will by you JSON structure. This one you can traverse
with an JSON_VISITOR, or if the structure is fixed you can validate
with assignment test the type and then do a forces assignment to the
respective value type.
For the xml I also have to look it up and I have to hurry right now,
will come back later.
Regards,
Rapha
Am Mittwoch, den 13.02.2019, 00:21 +0100 schrieb Os Paul:
> Dear Liberty Eiffel Mailing List Members,
>
> Could anyone send me some examples how to use the JSON parser
> included in Liberty Eiffel (src/lib/json)?
> I was not able to figure out which class to use. I'd mostly like to
> parse JSON from strings returned by C functions.
>
> I tried to use the XML parser too but got lost totally. Fortunately
> there are examples for this in the package but unfortunately
> those all read the XML from files. I'd like to parse something in
> memory/string. In all of the examples I saw references
> to 'URL'. I traced back these to STREAM but I got stuck there. How
> could I generate URL for something in memory?
>
> This part of the code in stream.e looked totally cryptic for me:
>
> --
> frozen url: URL
> -- The URL to this stream as resource
> do
> Result := url_memory
> if Result = Void then
> Result := new_url
> url_memory := Result
> end
> ensure
> not_void: Result /= Void
> always_the_same: Result = url
> end
>
> --
>
> Any help would be welcome.
>
> Thanks in advance & best regards,
> Paul
>
--
WhatsApp? Nein aber XMPP/Jabber!
App: Conversations
Kontakt: address@hidden