Jump to content
Sign in to follow this  
Gistya Eusebio

How to deal with JSON constants as integers

You are about to reply to a thread that has been inactive for 2581 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts


//JSON_TYPE integers
integer invalid = 90; //invalid
integer object = 91; //object
integer array = 92; //array
integer number = 93; //number
integer str = 94; //string
integer null = 95; //null
integer true = 96; //true
integer false = 97; //false

integer jsonType(string json, list specifiers) {
return (integer)llGetSubString(llEscapeURL(llJsonValueType(json,specifiers)),7,8);
}

This is going to let you get a JSON type as an integer instead of a string, so you can use bitwise comparisons or whatever you want.

Share this post


Link to post
Share on other sites

THIS is the superior version:

//JSON_TYPE integersinteger invalid = 1; //invalidinteger object  = 2; //objectinteger array   = 4; //arrayinteger number  = 8; //numberinteger str     = 16; //stringinteger null    = 32; //nullinteger true    = 64; //trueinteger false   = 128; //false//map the json type to a useful bitmask lolinteger jsonType(string json, list specifiers) {    return llRound(llPow(2.,(float)((integer)llGetSubString(        llEscapeURL(llJsonValueType(json,specifiers)),8,8))));}//as long as it ain't null or invalid, returns true |=}integer jsonValid(string value, list spec) {    return (        !(   jsonType(value,spec) & (invalid | null)   )    );}

 JSON type bitfields fun :D

Share this post


Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 2581 days.

Please take a moment to consider if this thread is worth bumping.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...