Difference between revisions of "Json"

From NWN Lexicon
Jump to: navigation, search
(Created page with "{{nwnee}}The '''json''' data type is used to manipulate complicated data structures in NWN, both existing objects and new "Nuklear UI" or "NUI" which do new GUI elements. This...")
 
Line 1: Line 1:
{{nwnee}}The '''json''' data type is used to manipulate complicated data structures in NWN, both existing objects and new "Nuklear UI" or "NUI" which do new GUI elements. This is only available in NWN:EE.
+
{{NWNEE}}The '''json''' data type is used to manipulate complicated data structures in NWN, both existing objects and new "Nuklear UI" or "NUI" which do new GUI elements. This is only available in NWN:EE.
  
 
You don't write the JSON directly as such (as a string for instance), but you can build it in NWN using the in built functions. You may also convert an object to JSON or import a JSON file built externally. You can also save and load the JSON from Sql.
 
You don't write the JSON directly as such (as a string for instance), but you can build it in NWN using the in built functions. You may also convert an object to JSON or import a JSON file built externally. You can also save and load the JSON from Sql.
  
You can dump the JSON you create to the log if you want to get it out of the game using [[WriteTimeStampLogEntry]]([[JsonDump]](jValue)) (printing it using SpeakString may remove some non-ASCII characters).
+
You can dump the JSON you create to the log if you want to get it out of the game using [[WriteTimestampedLogEntry]]([[JsonDump]](jValue)) (printing it using SpeakString may remove some non-ASCII characters).
  
 
There are a number of [[:Category:JSON_Functions|JSON Functions]] that can help manipulate, test, and alter strings.
 
There are a number of [[:Category:JSON_Functions|JSON Functions]] that can help manipulate, test, and alter strings.

Revision as of 01:58, 17 September 2021

Nwnee logo.jpg Note: This article documents Neverwinter Nights: Enhanced Edition new content or changes/updates/fixes to 1.69 functions. These are all listed under the category and patches pages.
The json data type is used to manipulate complicated data structures in NWN, both existing objects and new "Nuklear UI" or "NUI" which do new GUI elements. This is only available in NWN:EE.

You don't write the JSON directly as such (as a string for instance), but you can build it in NWN using the in built functions. You may also convert an object to JSON or import a JSON file built externally. You can also save and load the JSON from Sql.

You can dump the JSON you create to the log if you want to get it out of the game using WriteTimestampedLogEntry(JsonDump(jValue)) (printing it using SpeakString may remove some non-ASCII characters).

There are a number of JSON Functions that can help manipulate, test, and alter strings.


Example

// Retrieves the soundset.2da line used for oCreature, or -1 on error.
int GetCreatureSoundset(object oCreature)
{
    if(GetObjectType(oCreature) != OBJECT_TYPE_CREATURE) return -1;
 
    // Convert to JSON
    json jGet = ObjectToJson(oCreature);
 
    // Retrieve the key
    jGet = JsonObjectGet(jGet, "SoundSetFile");
 
    if(JsonGetType(jGet) == JSON_TYPE_NULL)
    {
        SpeakString("JsonObjectGet error 1: " + JsonGetError(jGet));
        return -1;
    }
 
    // Retrieve the value
    jGet = JsonObjectGet(jGet, "value");
 
    if(JsonGetType(jGet) != JSON_TYPE_INTEGER)
    {
        SpeakString("JsonObjectGet error 2: " + JsonGetError(jGet));
        return -1;
    }
 
    return JsonGetInt(jGet);
}


See Also

functions:

JSON Functions