簡體   English   中英

需要幫助使用json

[英]Need help using json

我在處理Jansson中的字符串和數組時遇到困難。

unsigned char number[10]; // contains a hex array using upto 6 bytes

現在我做了

json_object_set_new(foo,"bar",json_string(number));

這將導致一個空的json對象。

我也嘗試過

number[6]='\0';

其次是

json_object_set_new(foo,"bar",json_string(number));

但結果是一樣的。 我無法理解為什么。

樣品

#include <stdio.h>
#include <stdlib.h>
#include <jansson.h>

int main(void){
    unsigned char number[10] = "123456";
    char *result;
    json_t *root = json_object();
    json_t *foo = json_object();
    json_object_set(root, "foo", foo);
    json_object_set_new(foo,"bar",json_string(number));

    result = json_dumps(root, 0);
    printf("%s\n", result);//{"foo": {"bar": "123456"}}
    free(result);
    return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM