User Tools

Site Tools


vba:cast:json

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
vba:cast:json [23.11.2016 11:33:01]
yaslaw
vba:cast:json [16.01.2020 08:44:37] (current)
yaslaw
Line 1: Line 1:
 <​const>​ <​const>​
-    version=2.1.0 +    version=2.9.1 
-    vdate=23.11.2016+    vdate=16.01.2020
     fname=lib_json.bas     fname=lib_json.bas
     ns=%NAMESPACE%     ns=%NAMESPACE%
Line 12: Line 12:
 ==Version %%version%% %%vdate%%== ==Version %%version%% %%vdate%%==
  
-<​WRAP ​center ​round download>​ +<WRAP round download ​50%> 
-{{%%fname%%|Download %%fname%% (V-%%version%%)}} +><fc #​808080>//​Das Modul hat versteckte Attribute. Damit diese aktiv übernommen werden reicht es nicht aus, den Code in ein neues Modul zu kopieren. Man muss das Modul aus der Datei nach VBA importieren.//</​fc>​ 
-</​WRAP>​+>​{{popup>:​vba:​vba_importfile.png|Bild zum Import}} 
 + 
 +{{%%fname%%|Download %%fname%% (V-%%version%%)}}</​WRAP>​
  
 Für mehrere Projekte brauche ich JSON. Ich arbeitete bisher mit [[ http://​www.ediy.co.nz/​vbjson-json-parser-library-in-vb6-xidc55680.html|VB-JSON]]. Aber irgendwie störte es mich, dafür jeweils 2 Klassen und ein Modul zu kopieren. Für mehrere Projekte brauche ich JSON. Ich arbeitete bisher mit [[ http://​www.ediy.co.nz/​vbjson-json-parser-library-in-vb6-xidc55680.html|VB-JSON]]. Aber irgendwie störte es mich, dafür jeweils 2 Klassen und ein Modul zu kopieren.
Line 228: Line 230:
 ) )
 </​code>​ </​code>​
 +
 +=== 5) Wenn der String kein JSON-String ist ===
 +Wenn der übergeben String kein JSON-String ist, gibt es verschiedene Möglichkeiten
 +<code vb>'​Standard:​ Es wird kein Objekt erstellt
 +print_r json2obj("​abc"​)
 +<​Empty> ​
 +
 +'​String in ein Array parsen
 +print_r json2obj("​abc",​ jrtSingle2List)
 +<​Variant()> ​ (
 +    [0] => <​String>​ '​abc'​
 +)
 +
 +'​String in ein Dictionary parsen
 +print_r json2obj("​abc",​ jrtSingle2List + jrtDictionary)
 +<​Dictionary> ​ (
 +    [0] => <​String>​ '​abc'​
 +)</​code>​
 +
 +=== 6) Werte Nicht Casten ===
 +Normalerweise werdend ie Werte in passende Typen umgewandelt
 +<code vb>​print_r json2obj("​[Null,​True,​12.3]"​)
 +<​Variant()> ​ (
 +    [0] => <​Null> ​
 +    [1] => <​Boolean>​ True
 +    [2] => <​Double>​ 12.3
 +)</​code>​
 +Mittels jrtNotCastValue kann dies aber auch unterbunden werden
 +<code vb>​print_r json2obj("​[Null,​True,​12.3]",​ jrtNotCastValue)
 +<​Variant()> ​ (
 +    [0] => <​String>​ '​Null'​
 +    [1] => <​String>​ '​True'​
 +    [2] => <​String>​ '​12.3'​
 +)</​code>​
 +
 +=== 7) Leere Listen erstellen ===
 +<code vb>​print_r json2obj(null)
 +<​Empty> ​
 +
 +print_r json2obj(null,​jrtEmptyList)
 +<​Variant()> ​ ()
 +
 +print_r json2obj(empty,​jrtEmptyList)
 +<​Variant()> ​ ()
 +
 +print_r json2obj("​[1]",​jrtEmptyList)
 +<​Variant()> ​ (
 +    [0] => <​Byte>​ 1
 +)</​code>​
  
  
vba/cast/json.1479897181.txt.gz · Last modified: 23.11.2016 11:33:01 by yaslaw