主题
创建空的JSON数组 - JsonCreateArray
函数简介
创建一个空的JSON数组,用于构建JSON数组数据结构。
接口名称
JsonCreateArrayDLL调用
c
long JsonCreateArray();参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| 无参数 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int64_t arr = ola.JsonCreateArray();
if (arr != 0) {
// 先解析字符串元素,再追加到数组
int32_t perr = 0;
int64_t item1 = ola.JsonParse("\"apple\"", &perr);
ola.JsonArrayAppend(arr, item1);
int32_t strErr = 0;
std::string jsonOut = ola.JsonStringify(arr, 0, &strErr);
ola.JsonFree(arr);
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
long arr = ola.JsonCreateArray();
if (arr != 0)
{
// 先解析字符串元素,再追加到数组
int32_t perr = 0;
int64_t item1 = ola.JsonParse("\"apple\"", &perr);
ola.JsonArrayAppend(arr, item1);
int strErr;
string jsonOut = ola.JsonStringify(arr, 0, out strErr);
ola.JsonFree(arr);
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
arr = ola.JsonCreateArray()
if arr != 0:
ola.JsonArrayAppend(arr, ola.JsonParse('"apple"')[0])
ola.JsonArrayAppend(arr, ola.JsonParse('"banana"')[0])
json_out, str_err = ola.JsonStringify(arr, 0)
ola.JsonFree(arr)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long arr = ola.JsonCreateArray();
if (arr != 0) {
// 先解析字符串元素,再追加到数组
int32_t perr = 0;
int64_t item1 = ola.JsonParse("\"apple\"", &perr);
ola.JsonArrayAppend(arr, item1);
int strErr;
String jsonOut = ola.JsonStringify(arr, 0, strErr);
ola.JsonFree(arr);
}cpp
var ola = com("OlaPlug.OlaSoft")
var arr = ola.JsonCreateArray()
if(arr) {
// 先解析字符串元素,再追加到数组
int32_t perr = 0;
int64_t item1 = ola.JsonParse("\"apple\"", &perr);
ola.JsonArrayAppend(arr, item1);
var strErr = 0
var jsonOut = ola.JsonStringify(arr, 0, strErr)
ola.JsonFree(arr)
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
arr = ola.JsonCreateArray()
If arr <> 0 Then
// 先解析字符串元素,再追加到数组
int32_t perr = 0;
int64_t item1 = ola.JsonParse("\"apple\"", &perr);
ola.JsonArrayAppend(arr, item1);
strErr = 0
jsonOut = ola.JsonStringify(arr, 0, strErr)
ola.JsonFree(arr)
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
arr = ola.JsonCreateArray ()
.如果真 (arr ≠ 0)
// 先解析字符串元素,再追加到数组
int32_t perr = 0;
int64_t item1 = ola.JsonParse("\"apple\"", &perr);
ola.JsonArrayAppend(arr, item1);
strErr = 0
jsonOut = ola.JsonStringify (arr, 0, strErr)
ola.JsonFree (arr)
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var arr = ola.JsonCreateArray();
if(arr){
// 先解析字符串元素,再追加到数组
int32_t perr = 0;
int64_t item1 = ola.JsonParse("\"apple\"", &perr);
ola.JsonArrayAppend(arr, item1);
var strErr = 0;
var jsonOut = ola.JsonStringify(arr, 0, strErr);
ola.JsonFree(arr);
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 arr = ola.JsonCreateArray()
如果真 (arr ≠ 0)
{
// 先解析字符串元素,再追加到数组
int32_t perr = 0;
int64_t item1 = ola.JsonParse("\"apple\"", &perr);
ola.JsonArrayAppend(arr, item1);
整数 strErr = 0
文本型 jsonOut = ola.JsonStringify(arr, 0, strErr)
ola.JsonFree(arr)
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int64_t arr = ola.JsonCreateArray();
if (arr != 0) {
// 先解析字符串元素,再追加到数组
int32_t perr = 0;
int64_t item1 = ola.JsonParse("\"apple\"", &perr);
ola.JsonArrayAppend(arr, item1);
int32_t strErr = 0;
std::string jsonOut = ola.JsonStringify(arr, 0, &strErr);
ola.JsonFree(arr);
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long arr = JsonCreateArray(instance);
if (arr != 0) {
int err = 0;
long item = JsonParse(instance, "\"apple\"", &err);
JsonArrayAppend(instance, arr, item);
long ptr = JsonStringify(instance, arr, 0, 0);
if (ptr != 0) {
char buffer[512] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}
JsonFree(instance, arr);
}csharp
long instance = CreateCOLAPlugInterFace();
long arr = JsonCreateArray(instance);
if (arr != 0) {
int err = 0;
long item = JsonParse(instance, "\"apple\"", &err);
JsonArrayAppend(instance, arr, item);
long ptr = JsonStringify(instance, arr, 0, 0);
if (ptr != 0) {
char buffer[512] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}
JsonFree(instance, arr);
}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()
arr = ola.JsonCreateArray(instance)
if arr:
err = c_int(0)
item = ola.JsonParse(instance, b'"apple"', err)
ola.JsonArrayAppend(instance, arr, item)
ptr = ola.JsonStringify(instance, arr, 0, err)
if ptr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(ptr, buf, 512)
ola.FreeStringPtr(ptr)
ola.JsonFree(instance, arr)返回值
| 返回值 | 说明 |
|---|---|
非 0 | 返回 新创建的JSON数组句柄。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 释放内存 | 返回的JSON数组句柄需要调用 JsonFree 释放内存。 |
| 创建失败时返回0 | 创建失败时返回0,需要检查返回值。 |
