Jump to content

How to deal with JSON constants as integers


Gistya Eusebio
 Share

You are about to reply to a thread that has been inactive for 3967 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.

Link to comment
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

Link to comment
Share on other sites

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...