English
Source / code snippets

Json Parse

 

Michael
W.
If one only small Json-Objects/lists of a Programmteil to that others weiterreichen would like, then is Create("Json" really something umständlich.

there would I me the Json.Parse() wish.

It's all right naturally too so

cls
/*
js& = Json("Parse", jsonstring$)
here becomes Create("Json",filename$) uses circa a String one Json-Objekt or a Json-list To transform.
The File thereby same again removes.
js is the ID the Json-Objektes. whether it worked has: if(js&,"I'm happy","That's ugly") // request works with Json("Parse",s) and with Create("Json",fn$)
*/
SubProc Json.Parse1
Parameters string jsonstring
Declare string s, Dateiname, Content, long js
s = Translate$(dt("getDate",5)," ","_")
s = Translate$(s,",","_")
s = Translate$(s,":","_")
s = Translate$(s,"+","p")
s = Translate$(s,"-","m")
s = Translate$(s,"__","_")
MkDir "C:\\Temp"
Case %ioresult <> 0 : js = 0
Dateiname = "C:\\Temp\\JSON_" + s + ".json"
' print "File:",Dateiname

// File in the temp. directory create
Case %ioresult <> 0 : js = 0
Assign #9, Dateiname
Case %ioresult <> 0 : js = 0
Rewrite #9
Case %ioresult <> 0 : js = 0
// desired Json-String File write
Content = Utf8Encode(jsonstring + "\n")
print #9, Content
//
Case %ioresult <> 0 : js = 0
Close #9
Case %ioresult <> 0 : js = 0
Sleep 100

// Json-Objekt from the String "jsonstring" create
js = Create("Json",Dateiname)
Case %ioresult <> 0 : fh = 0
Sleep 100

// File again Remove (or to control keep)
' Erase #9
Case %ioresult <> 0 : fh = 0

Return js // The ID the Objektes or. the list give back
ENDPROC
//
Declare long js, cnt, string s

s = "{\qr\q:255, \qg\q:160, \qb\q:80}"

js = Json("Parse1",s)
print "js:",js
cnt = Json("Count", js)
print "count:",cnt
print "To parsen:",s
print "Result:"
WhileLoop 0, cnt - 1
print " ",Json("name", js, &loop),":", Json("Value", js, &loop)
EndWhile
print "Objekt:",Json("Text",js,0),"\n"
waitkey
end

small Test angefügt.

this short example goes Yes yet, but something longer is a plainer String rather.
Declare long js
js = Create("Json")
Json("AddNumber", js, "r", 255)
Json("AddNumber", js, "g", 160)
Json("AddNumber", js, "b",  80)
 
System: Windows 8/10, XProfan X4
Programmieren, das spannendste Detektivspiel der Welt.
11/18/20  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

1.630 Views

Untitledvor 0 min.
H.Brill04/03/23
Cyberangle02/03/23
Normann Strübli01/31/23
ByteAttack12/30/22
More...

Themeninformationen

this Topic has 1 subscriber:

Michael W. (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie