From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a5d:9801:: with SMTP id a1mr5110445iol.31.1543283265494; Mon, 26 Nov 2018 17:47:45 -0800 (PST) X-Received: by 2002:a9d:5403:: with SMTP id j3mr465860oth.2.1543283265345; Mon, 26 Nov 2018 17:47:45 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.166.215.MISMATCH!k10no124651itk.0!news-out.google.com!y103-v6ni86ita.0!nntp.google.com!q69no124594itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 26 Nov 2018 17:47:45 -0800 (PST) In-Reply-To: <9524b3ee-476f-4af6-ab83-b15a6c2a417c@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=151.249.135.130; posting-account=M7mWIgoAAACGA_Fxpu1-vAqIUttmwREB NNTP-Posting-Host: 151.249.135.130 References: <9524b3ee-476f-4af6-ab83-b15a6c2a417c@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: GNATCOLL JSON Parsing From: eduardsapotski@gmail.com Injection-Date: Tue, 27 Nov 2018 01:47:45 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:54908 Date: 2018-11-26T17:47:45-08:00 List-Id: There is no limit to human stupidity. I spent two days studying different ada-libs to parse json. It ended up by myself wrote function in 40 lines. Spent one hour. function Get_Pair_Settings return Pair_Settings_Vector_Package.Vector is package List_Strings is new Vectors(Count_Type, Unbounded_String); JSON_Text : Unbounded_String := Message_Body(Get("http://api.exmo.com/v1/pair_settings")); S : Unbounded_String := Null_Unbounded_String; List : List_Strings.Vector; Count : Count_Type := 0; Result : Pair_Settings_Vector_Package.Vector; begin for i in 1 .. Length(JSON_Text) loop if Element(JSON_Text, i) /= ' ' and Element(JSON_Text, i) /= '{' and Element(JSON_Text, i) /= '}' and Element(JSON_Text, i) /= '"' then if Element(JSON_Text, i) = ',' or Element(JSON_Text, i) = ':' then List.Append(S); S := Null_Unbounded_String; else Append(S, Element(JSON_Text, i)); end if; end if; end loop; List.Append(S); while Count <= List.Length - 1 loop declare PS : Pair_Setting; begin PS.Pair_ID := List.Element(Count); PS.Min_Quantity := Money_Type'Value(To_String(List.Element(Count + 2))); PS.Max_Quantity := Money_Type'Value(To_String(List.Element(Count + 4))); PS.Min_Price := Money_Type'Value(To_String(List.Element(Count + 6))); PS.Max_Price := Money_Type'Value(To_String(List.Element(Count + 8))); PS.Max_Amount := Money_Type'Value(To_String(List.Element(Count + 10))); PS.Min_Amount := Money_Type'Value(To_String(List.Element(Count + 12))); Result.Append(PS); end; Count := Count + 13; end loop; return Result; end;