主题
设置JSON对象中的布尔值 - JsonSetBool
函数简介
设置JSON对象中指定键的布尔值。
接口名称
JsonSetBoolDLL调用
c
int JsonSetBool(long obj, string key, int value);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| obj | 长整数型 | JSON对象句柄。 |
| key | 字符串 | 键名。 |
| value | 整数型 | 布尔值(0表示false,非0表示true)。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int64_t root = ola.JsonCreateObject();
if (root != 0) {
int ret = ola.JsonSetBool(root, "enabled", 1); // 1=true, 0=false
int32_t strErr = 0;
std::string jsonOut = ola.JsonStringify(root, 0, &strErr);
ola.JsonFree(root);
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
long root = ola.JsonCreateObject();
if (root != 0)
{
int ret = ola.JsonSetBool(root, "enabled", 1); // 1=true, 0=false
int strErr;
string jsonOut = ola.JsonStringify(root, 0, out strErr);
ola.JsonFree(root);
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
root = ola.JsonCreateObject()
if root != 0:
ret = ola.JsonSetBool(root, "enabled", 1) # 1=true, 0=false
json_out, str_err = ola.JsonStringify(root, 0)
ola.JsonFree(root)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long root = ola.JsonCreateObject();
if (root != 0) {
int ret = ola.JsonSetBool(root, "enabled", 1); // 1=true, 0=false
int strErr;
String jsonOut = ola.JsonStringify(root, 0, strErr);
ola.JsonFree(root);
}cpp
var ola = com("OlaPlug.OlaSoft")
var root = ola.JsonCreateObject()
if(root) {
int ret = ola.JsonSetBool(root, "enabled", 1); // 1=true, 0=false
var strErr = 0
var jsonOut = ola.JsonStringify(root, 0, strErr)
ola.JsonFree(root)
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
root = ola.JsonCreateObject()
If root <> 0 Then
int ret = ola.JsonSetBool(root, "enabled", 1); // 1=true, 0=false
strErr = 0
jsonOut = ola.JsonStringify(root, 0, strErr)
ola.JsonFree(root)
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
root = ola.JsonCreateObject ()
.如果真 (root ≠ 0)
int ret = ola.JsonSetBool(root, "enabled", 1); // 1=true, 0=false
strErr = 0
jsonOut = ola.JsonStringify (root, 0, strErr)
ola.JsonFree (root)
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var root = ola.JsonCreateObject();
if(root){
int ret = ola.JsonSetBool(root, "enabled", 1); // 1=true, 0=false
var strErr = 0;
var jsonOut = ola.JsonStringify(root, 0, strErr);
ola.JsonFree(root);
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 root = ola.JsonCreateObject()
如果真 (root ≠ 0)
{
int ret = ola.JsonSetBool(root, "enabled", 1); // 1=true, 0=false
整数 strErr = 0
文本型 jsonOut = ola.JsonStringify(root, 0, strErr)
ola.JsonFree(root)
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int64_t root = ola.JsonCreateObject();
if (root != 0) {
int ret = ola.JsonSetBool(root, "enabled", 1); // 1=true, 0=false
int32_t strErr = 0;
std::string jsonOut = ola.JsonStringify(root, 0, &strErr);
ola.JsonFree(root);
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long root = JsonCreateObject(instance);
if (root != 0) {
JsonSetString(instance, root, "username", "ola");
JsonSetBool(instance, root, "enabled", 1);
long ptr = JsonStringify(instance, root, 0, 0);
if (ptr != 0) {
char buffer[512] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}
JsonFree(instance, root);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long JsonCreateObject(long ola);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int JsonSetString(long ola, long obj, string key, string value);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int JsonSetBool(long ola, long obj, string key, int value);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long JsonStringify(long ola, long obj, int indent, int err);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int JsonFree(long ola, long obj);
long instance = CreateCOLAPlugInterFace();
long root = JsonCreateObject(instance);
if (root != 0) {
JsonSetString(instance, root, "username", "ola");
JsonSetBool(instance, root, "enabled", 1);
long ptr = JsonStringify(instance, root, 0, 0);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
}
JsonFree(instance, root);
}python
root = ola.JsonCreateObject(instance)
if root:
ola.JsonSetString(instance, root, b"username", b"ola")
ola.JsonSetBool(instance, root, b"enabled", 1)
err = c_int(0)
ptr = ola.JsonStringify(instance, root, 0, err)
if ptr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(ptr, buf, 512)
ola.FreeStringPtr(ptr)
ola.JsonFree(instance, root)返回值
| 返回值 | 说明 |
|---|---|
0 | 成功。 |
| 其他 | 错误码,失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 如果 key 已存在 | 如果 key 已存在,会覆盖原有值。 |
