lifuhua666666 发表于 2012-11-09 11:01

json库安装问题?(不知的安装那个库)

网上下的isac-menu.cpp,编译需要json库,但不知到用那个?

错误如下:
dialogs/isac-menu.cpp:3681: error: ‘JSONOBJECT’ was not declared in this scope
dialogs/isac-menu.cpp:3681: error: expected ‘;’ before ‘o’
dialogs/isac-menu.cpp:3699: warning: comparison with string literal results in unspecified behaviour
dialogs/isac-menu.cpp:3704: error: ‘o’ was not declared in this scope
dialogs/isac-menu.cpp:3705: error: ‘o’ was not declared in this scope
dialogs/isac-menu.cpp:3707: error: ‘o’ was not declared in this scope
dialogs/isac-menu.cpp:3710: error: ‘JSONVALUE’ was not declared in this scope
dialogs/isac-menu.cpp: In function ‘gchar* isac_get_clone_syntax(gchar*, SPWidget*)’:
dialogs/isac-menu.cpp:3720: error: ‘JSONOBJECT’ was not declared in this scope
dialogs/isac-menu.cpp:3720: error: expected ‘;’ before ‘o’
dialogs/isac-menu.cpp:3721: error: ‘JSONARRAY’ was not declared in this scope
dialogs/isac-menu.cpp:3721: error: expected ‘;’ before ‘ja’
dialogs/isac-menu.cpp:3734: error: ‘ja’ was not declared in this scope
dialogs/isac-menu.cpp:3740: warning: comparison with string literal results in unspecified behaviour
dialogs/isac-menu.cpp:3747: error: ‘o’ was not declared in this scope
dialogs/isac-menu.cpp:3748: error: ‘o’ was not declared in this scope
dialogs/isac-menu.cpp:3750: error: ‘o’ was not declared in this scope
dialogs/isac-menu.cpp:3750: error: ‘ja’ was not declared in this scope
dialogs/isac-menu.cpp:3750: error: ‘JSONVALUE’ was not declared in this scope
dialogs/isac-menu.cpp: In function ‘gchar* isac_get_color_syntax(gchar*, SPWidget*)’:

isac-menu.cpp部分源码如下:
gchar* isac_get_bar_syntax (gchar *syntax, SPWidget *spw)
{
    JSONOBJECT o;
    std::string svalue;
    GtkWidget *wg;
    gchar const *tag, *min, *max, *jsyntax;
   
    wg = GTK_WIDGET(gtk_object_get_data (GTK_OBJECT (spw), "isac_bar_tag"));
    tag = gtk_entry_get_text (GTK_ENTRY (wg));
   
    wg = GTK_WIDGET(gtk_object_get_data (GTK_OBJECT (spw), "isac_bar_min"));
    min = gtk_entry_get_text (GTK_ENTRY (wg));
   
    wg = GTK_WIDGET(gtk_object_get_data (GTK_OBJECT (spw), "isac_bar_max"));
    max = gtk_entry_get_text (GTK_ENTRY (wg));
   
    gchar *dsb = (gchar*)(gtk_object_get_data (GTK_OBJECT (spw), "isac_bar_dsb"));
   
    if(strlen(g_strdup_printf("%s",tag))==0) return syntax;
   
    if(syntax!="")
    {
      syntax = g_strconcat(syntax, ",", NULL);
    }
   
    if(strcmp(dsb, "0")==0) o["attr"] = "bar";
    else o["@ttr"] = "bar";
   
    o["tag"] = tag;
    o["min"] = atoi(min);
    o["max"] = atoi(max);
    JSONVALUE(o).ToString(svalue, 0);
    jsyntax = svalue.c_str();
   
    return g_strconcat(syntax, (gchar*)jsyntax, NULL);
}

gchar*
isac_get_clone_syntax (gchar *syntax, SPWidget *spw)
{
   
    JSONOBJECT o;
    JSONARRAY ja;
    std::string svalue;
   
    gchar const *mapstring="", *mapfrom="", *mapto="", *jsyntax;
   
    for(guint i=0;i<g_slist_length(clone_mapfrom_list);i++)
    {
      mapfrom = g_strstrip(g_strdup(gtk_entry_get_text (GTK_ENTRY (g_slist_nth_data(clone_mapfrom_list,i)))));
      mapto = g_strstrip(g_strdup(gtk_entry_get_text (GTK_ENTRY (g_slist_nth_data(clone_mapto_list,i)))));

      if(strlen(mapfrom) != 0 || strlen(mapto) != 0 )
      {
            mapstring = g_strconcat("%", mapfrom, "=", mapto, NULL);
            ja.push_back(mapstring);
      }
    }
   
    if(strlen(mapstring)==0) return syntax;   

    if(syntax!="")
    {
      syntax = g_strconcat(syntax, ",", NULL);
    }
   
    gchar *dsb = (gchar*)(gtk_object_get_data (GTK_OBJECT (spw), "isac_clone_dsb"));
   
    if(strcmp(dsb, "0")==0) o["attr"] = "clone";
    else o["@ttr"] = "clone";
   
    o["map"] = JSONVALUE(ja);
    JSONVALUE(o).ToString(svalue, 0);
    jsyntax = svalue.c_str();
   
    return g_strconcat(syntax, (gchar*)jsyntax, NULL);
}


gchar*
isac_get_color_syntax (gchar *syntax, SPWidget *spw)
{
    JSONOBJECT o, oarray;
    JSONARRAY ja;
    std::string svalue;
    GtkTreeModel *model;
    GtkTreeIter iter;
    GtkTreePath *path;
    char *tag, *value, *code;   
    gchar const *jsyntax;

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (color_list));
    path = gtk_tree_path_new_first ();
   
    if(!gtk_tree_model_get_iter(model, &iter, path)){
      return syntax;
    }

    while(gtk_tree_model_get_iter(model, &iter, path)){
      
      gtk_tree_model_get(model, &iter, 0, &tag, 2, &value, 4, &code, -1);
      
      if(strlen(tag) != 0 && strlen(value) != 0 && strlen(code) != 0 )
      {
            oarray["tag"] = tag;
            oarray["data"] = value;
            oarray["param"] = code;
            ja.push_back(oarray);
      }
      
      else {
            oarray["tag"] = tag;
            oarray["data"] = value;
            oarray["param"] = code;
            ja.push_back(oarray);
      }
      gtk_tree_path_next (path);
    }
   
    if(syntax!="")
    {
      syntax = g_strconcat(syntax, ",", NULL);
    }
   
    isac_validate_color(spw);
    gchar *dsb = (gchar*)(gtk_object_get_data (GTK_OBJECT (spw), "isac_color_dsb"));
   
    if(strcmp(dsb, "0")==0) o["attr"] = "color";
    else o["@ttr"] = "color";
   
    o["list"] = JSONVALUE(ja);
    JSONVALUE(o).ToString(svalue, 0);
    jsyntax = svalue.c_str();
   
    return g_strconcat(syntax, (gchar*)jsyntax, NULL);
}

gchar*
isac_get_function_syntax (gchar *syntax, SPWidget *spw)
{
    GtkWidget *wg;
    gchar const *name, *effect, *param;
   
    wg = GTK_WIDGET(gtk_object_get_data (GTK_OBJECT (spw), "isac_func_name"));
    name = gtk_entry_get_text (GTK_ENTRY (wg));

    wg = GTK_WIDGET(gtk_object_get_data (GTK_OBJECT (spw), "isac_func_param"));
    param = gtk_entry_get_text (GTK_ENTRY (wg));
   
    gchar *formparam;// = reformat_backspc(param);

    if(strlen(g_strdup_printf("%s%s",name,param))==0) /* && strcmp(effect,"Shadow")==0)*/ return syntax;
   
    if(syntax!="")
    {
      syntax = g_strconcat(syntax, ",", NULL);
    }

    gchar *dsb = (gchar*)(gtk_object_get_data (GTK_OBJECT (spw), "isac_func_dsb"));
   
    if(strcmp(dsb,"0")==0)
      //return g_strconcat(syntax, "{attr:\"function\",name:\"",g_ascii_strdown(name,strlen(name)),"\",param:[\"",g_ascii_strdown(formparam,strlen(formparam)),"\"]",",effect:\"", g_ascii_strdown(effect,strlen(effect)),"\"}",NULL);

lifuhua666666 发表于 2012-11-09 11:03

求高人指点啊。需要使用那个库?

linux_c_py_php 发表于 2012-11-10 00:38

json-c是你不二的选择.

lifuhua666666 发表于 2012-11-12 17:35

回复 3# linux_c_py_php


    我们在网上下的源码,想添加到我们程序中,是c++的,里面由JSONOBJECT, JSONVALUE, JSONARRAY等,如何确定是使用的那一个json库啊(源码中未说明)?
如果使用其他的库,那需要改的就太多了。

lifuhua666666 发表于 2012-11-14 19:34

本帖最后由 lifuhua666666 于 2012-11-14 19:34 编辑

最终我使用jsoncpp库,添加定义如下:
typedef Json::Value        JSONOBJECT;
typedef Json::Value        JSONVALUE;
typedef Json::Value        JSONARRAY;

并少量修改源码,可以满足需求。
页: [1]
查看完整版本: json库安装问题?(不知的安装那个库)