主题
设置JSON对象中的数值 - JsonSetNumber
函数简介
设置JSON对象中指定键的数值。
接口名称
JsonSetNumberDLL调用
c
int JsonSetNumber(long obj, string key, double value);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| obj | 长整数型 | JSON对象句柄。 |
| key | 字符串 | 键名。 |
| value | 双精度浮点数 | 数值。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int64_t root = ola.JsonCreateObject();
if (root != 0) {
int ret = ola.JsonSetNumber(root, "level", 10);
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.JsonSetNumber(root, "level", 10);
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.JsonSetNumber(root, "level", 10)
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.JsonSetNumber(root, "level", 10);
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.JsonSetNumber(root, "level", 10);
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.JsonSetNumber(root, "level", 10);
strErr = 0
jsonOut = ola.JsonStringify(root, 0, strErr)
ola.JsonFree(root)
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
root = ola.JsonCreateObject ()
.如果真 (root ≠ 0)
int ret = ola.JsonSetNumber(root, "level", 10);
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.JsonSetNumber(root, "level", 10);
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.JsonSetNumber(root, "level", 10);
整数 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.JsonSetNumber(root, "level", 10);
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) {
JsonSetNumber(instance, root, "level", 10);
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
long instance = CreateCOLAPlugInterFace();
long root = JsonCreateObject(instance);
if (root != 0) {
JsonSetNumber(instance, root, "level", 10);
long ptr = JsonStringify(instance, root, 0, 0);
if (ptr != 0) {
char buffer[512] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}
JsonFree(instance, root);
}python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
root = ola.JsonCreateObject(instance)
if root:
ola.JsonSetNumber(instance, root, b"level", 10)
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 已存在,会覆盖原有值。 |
| 支持整数和浮点数 | 支持整数和浮点数。 |
