1

私は mjson ライブラリ ( http://mjson.sourceforge.net/ ) を使用して、簡単な json エンコーディングを行っています。json 出力は次のようになります。

{「タイプ」:「mytype」、「ホスト名」:「myhostname」...「状態」:「mystate」}

私の関数 return {}、またはこの例に基づいて: http://mjson.sourceforge.net/examples.html 関数を returnにしstate : "state : "myState" { "type" : "mytype" ....ます。状態は配列の外側にあります。

ここで私のエンコーディング関数:

json_t *make_LogEntryToJson( NAGIOS_LOGENTRY *logEntry )
{

    json_t *entry, *label, *value ;

    // create an entry node
    entry = json_new_object();

    // insert the first label-value pair
    label = json_new_string("type");
    value = json_new_string( logEntry -> type );
    json_insert_child( label, value);
    json_insert_child(entry, label );

    // insert the second label-value pair
    label = json_new_string("hostname");
    value = json_new_string( logEntry -> hostname );
    json_insert_child( label, value);
    json_insert_child(entry, label );

    // insert the second label-value pair
    label = json_new_string("srvname");
    value = json_new_string(logEntry -> srvname);
    json_insert_child( label, value);
    json_insert_child(entry, label );

    // insert the second label-value pair
    label = json_new_string("libelle");
    value = json_new_string( logEntry -> libelle );
    json_insert_child( label, value);
    json_insert_child(entry, label );

    // insert the second label-value pair
    label = json_new_string("timestamp");
    value = json_new_string( logEntry -> timestamp );
    json_insert_child( label, value);
    json_insert_child(entry, label );

    // insert the second label-value pair
    label = json_new_string("stateType");
    value = json_new_string( logEntry -> stateType );
    json_insert_child( label, value);
    json_insert_child(entry, label );

    // insert the second label-value pair
    label = json_new_string("state");
    value = json_new_string( logEntry -> state );
    json_insert_child( label, value);
    json_insert_child(entry, label );

    return entry ;
}

どんな助けでも大歓迎です!

4

0 に答える 0