From 20296179e7925a54933e8aab0706cbe582fa92a9 Mon Sep 17 00:00:00 2001 From: Kem Tekinay Date: Fri, 9 Dec 2016 14:35:44 -0500 Subject: [PATCH] Added ToNativeValue computed property and ParseJSON shared method --- JSONItem_MTC.xojo_xml_code | 94 +++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 6 deletions(-) diff --git a/JSONItem_MTC.xojo_xml_code b/JSONItem_MTC.xojo_xml_code index c902fa7..ea0ab60 100644 --- a/JSONItem_MTC.xojo_xml_code +++ b/JSONItem_MTC.xojo_xml_code @@ -1,8 +1,8 @@ - + JSONItem_MTC - 0 + 1447604198 1 1 0 @@ -2225,6 +2225,24 @@ outMBs() As MemoryBlock, ByRef outIndex As Integer MemoryBlock + + ParseJSON + + 1 + + 134217984 + Shared Function ParseJSON(s As String) As Variant + dim j as new JSONItem_MTC( s ) + return j.ToNativeValue + End Function + + 134217984 + + 0 + 1 + s As String + Variant + Legal @@ -2334,7 +2352,7 @@ 1 134217984 - Compact As Boolean + Compact As Boolean = True 134217984 @@ -2362,7 +2380,7 @@ 1 134217984 - EscapeSlashes As Boolean + EscapeSlashes As Boolean = True 134217984 @@ -2390,7 +2408,7 @@ 1 134217984 - IndentSpacing As Integer + IndentSpacing As Integer = 2 134217984 @@ -2472,7 +2490,7 @@ 1 134217984 - EncodeUnicode As EncodeType + EncodeUnicode As EncodeType = EncodeType.JavaScriptCompatible 134217984 @@ -2581,6 +2599,70 @@ End Get + + ToNativeValue + + 1 + + 134217984 + Property ToNativeValue As Variant + + + 134217984 + ToNativeValue As Variant + 0 + 0 + + 134217984 + Set + + End Set + + + 134217984 + Get + if IsObject then + dim d as new Dictionary + + dim rawKeys() as variant = ObjectValues.Keys + dim values() as variant = ObjectValues.Values + + for i as integer = 0 to rawKeys.Ubound + dim name as string = KeyToName( rawKeys( i ) ) + dim value as variant = values( i ) + + if value isa JSONItem_MTC then + value = JSONItem_MTC( value ).ToNativeValue + end if + + d.Value( name ) = value + next + + return d + + elseif IsArray then + dim arr() as variant + redim arr( ArrayValues.Ubound ) + + for i as integer = 0 to ArrayValues.Ubound + dim value as variant = ArrayValues( i ) + if value isa JSONItem_MTC then + value = JSONItem_MTC( value ).ToNativeValue + end if + + arr( i ) = value + next + + return arr + + else + + return nil + + end if + End Get + + Compact