当前位置: 首页>>代码示例>>C++>>正文


C++ JSONArray::push_back方法代码示例

本文整理汇总了C++中JSONArray::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONArray::push_back方法的具体用法?C++ JSONArray::push_back怎么用?C++ JSONArray::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JSONArray的用法示例。


在下文中一共展示了JSONArray::push_back方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: api_hdd_handler

void api_hdd_handler(const shared_ptr<restbed::Session> session)
{
  Hdd *hdd;
  JSONArray devices;
  JSONObject obj;
  JSONObject deviceData;
  JSONValue *output;
  double hddTotal;
  double hddUsage;
  vector<string> hddDevices;

  hdd = Hdd::getInstance();
  hddTotal = hdd->getTotalCapacity();
  hddUsage = hdd->getUsedCapacity();
  hddDevices = hdd->getListHardDrive();
  obj[L"total"] = new JSONValue(hddTotal);
  obj[L"usage"] = new JSONValue(hddUsage);
  for (vector<string>::iterator it = hddDevices.begin(); it != hddDevices.end(); ++it)
  {
    deviceData[L"name"] = new JSONValue(s2ws(*it));
    devices.push_back(new JSONValue(deviceData));
  }
  obj[L"devices"] = new JSONValue(devices);
  output = new JSONValue(obj);
  session->close(restbed::OK, ws2s(output->Stringify()), { { "Content-Type", "application/json" } });
}
开发者ID:niou128,项目名称:my_config,代码行数:26,代码来源:main.cpp

示例2: GetJsonStr

/*
{
"contents": [{
"Test": "Test,Obj"
},
"HelloWorld,cswuyg",
"Good Good Studey,Day Day Up"],
"result": "no_way"
}
*/
std::wstring CTestJSON::GetJsonStr()
{
	JSONArray jsArray;
	JSONObject jsObj;
	jsObj[L"Test"] = new(std::nothrow)JSONValue(L"Test,Obj");
	jsArray.push_back(new(std::nothrow)JSONValue(jsObj));
	jsArray.push_back(new(std::nothrow)JSONValue(L"HelloWorld,cswuyg"));
	jsArray.push_back(new(std::nothrow)JSONValue(L"Good Good Studey,Day Day Up"));
	jsArray.push_back(new(std::nothrow)JSONValue((double)1988));

	JSONObject jsObjNew;
	jsObjNew[L"contents"] = new(std::nothrow)JSONValue(jsArray);
	jsObjNew[L"result"] = new(std::nothrow)JSONValue(L"no_way");

	JSONValue jsValue = jsObjNew;
	std::wstring strRet = jsValue.Stringify().c_str();
	return strRet;
}
开发者ID:BillXu,项目名称:simple_win,代码行数:28,代码来源:test.cpp

示例3: fromPoint

JSON::JSONArray JSON::fromPoint(const Point& point)
{
    JSONArray array;

    array.push_back(fromNumber(point.x()));
    array.push_back(fromNumber(point.y()));

    return array;
}
开发者ID:winniehell-wasteland,项目名称:max-min-edge-length-triangulation,代码行数:9,代码来源:json.cpp

示例4: initArrayFromStream

// Initialize a JSON array from a stream
// This is similar to initFromStream() above and may also be called
// recursively by way of initValueFromStream()
// The expectation is that the first character will be a '[' and it
// will run until if finds a matching ']' char.  Along the way it
// may create nested objects and/or arrays.
// Note: It will consume the closing bracket from the stream
void initArrayFromStream(JSONArray &arr, istream &istr) {
  char nextChar;
  istr >> nextChar;
  checkChar(nextChar, '['); // sanity check
  skipWhiteSpace(istr);

  // Check for empty array (and make sure we consume the ])
  nextChar = static_cast<char>(istr.peek());
  if (nextChar == ']') {
    istr.ignore();
  }

  while (nextChar != ']') // process the stream
  {
    // Quick sanity check
    if (istr.eof()) {
      throw JSONParseException("Unexpected end of data stream");
    }

    // We expect to start the loop with the stream pointing to the
    // first character of the value
    // Add the value to our array
    arr.push_back(initValueFromStream(istr));

    istr >> nextChar;
    // nextChar is guaranteed to be either a comma, close brace or close
    // bracket.
    //(If it was anything else, initValueFromStream() would have thrown an
    // exception.)
    // A brace is an error, a bracket means the array is done (and will be
    // checked at
    // the start of the while loop) and a comma needs to be thrown out (along
    // with any
    // following whitespace) to position us for the next value
    if (nextChar == '}')
      throw JSONParseException(
          "Invalid closing brace while initializing array");
    else if (nextChar == ',') {
      skipWhiteSpace(istr);
      // Check to see if another key/value pair really follows the comma
      // (because if one doesn't, the parser will get screwed up and may not
      // actually detect the problem).
      if (istr.peek() == ']') {
        throw JSONParseException(
            "Invalid comma (array ended with no further values)");
      }
    }
  }
}
开发者ID:liyulun,项目名称:mantid,代码行数:56,代码来源:SimpleJSON.cpp

示例5: serialize_data

std::string serialize_data(data_t *data) {
    std::lock_guard<std::mutex> lk(data->m);

    JSONObject root;

    JSONObject states;
    states[L"isBlink"] = new JSONValue(data->isBlink);
    states[L"isLeftWink"] = new JSONValue(data->isLeftWink);
    states[L"isRightWink"] = new JSONValue(data->isRightWink);
    states[L"isLookingLeft"] = new JSONValue(data->isLookingLeft);
    states[L"isLookingRight"] = new JSONValue(data->isLookingRight);

    JSONObject expressiv;

    expressiv[L"lowerFaceActionName"] = new JSONValue(s2w(data->lowerFaceActionName));
    expressiv[L"lowerFaceAction"] = new JSONValue((double) data->lowerFaceAction);
    expressiv[L"lowerFaceActionPower"] = new JSONValue(data->lowerFaceActionPower);
    expressiv[L"upperFaceActionName"] = new JSONValue(s2w(data->upperFaceActionName));
    expressiv[L"upperFaceAction"] = new JSONValue((double) data->upperFaceAction);
    expressiv[L"upperFaceActionPower"] = new JSONValue(data->upperFaceActionPower);

    root[L"time"] = new JSONValue(data->timestamp);
    root[L"battery"] =  new JSONValue(data->battery);
    root[L"wirelessSignal"] = new JSONValue((double)(data->wireless_signal));
    root[L"states"] = new JSONValue(states);
    root[L"expressiv"] = new JSONValue(expressiv);

    JSONArray array;
    for (int i = 0; i < data->cq.size(); i++) {
        array.push_back(new JSONValue((double) data->cq[i]));
    }
    root[L"contactQuality"] = new JSONValue(array);

    JSONValue *value = new JSONValue(root);
    std::wstring out = value->Stringify();


    std::string ss;
    ss.assign(out.begin(), out.end());

    delete value;

    return ss;
}
开发者ID:rbtying,项目名称:emotiv_node,代码行数:44,代码来源:serv.cpp

示例6: JSONValue


//.........这里部分代码省略.........
            object[name] = value;

            // More whitespace?
            if (!JSON::SkipWhitespace(data))
            {
                FREE_OBJECT(object);
                return NULL;
            }

            // End of object?
            if (**data == L'}')
            {
                (*data)++;
                return new JSONValue(object);
            }

            // Want a , now
            if (**data != L',')
            {
                FREE_OBJECT(object);
                return NULL;
            }

            (*data)++;
        }

        // Only here if we ran out of data
        FREE_OBJECT(object);
        return NULL;
    }

    // An array?
    else if (**data == L'[')
    {
        JSONArray array;

        (*data)++;

        while (**data != 0)
        {
            // Whitespace at the start?
            if (!JSON::SkipWhitespace(data))
            {
                FREE_ARRAY(array);
                return NULL;
            }

            // Special case - empty array
            if (array.size() == 0 && **data == L']')
            {
                (*data)++;
                return new JSONValue(array);
            }

            // Get the value
            JSONValue *value = Parse(data);
            if (value == NULL)
            {
                FREE_ARRAY(array);
                return NULL;
            }

            // Add the value
            array.push_back(value);

            // More whitespace?
            if (!JSON::SkipWhitespace(data))
            {
                FREE_ARRAY(array);
                return NULL;
            }

            // End of array?
            if (**data == L']')
            {
                (*data)++;
                return new JSONValue(array);
            }

            // Want a , now
            if (**data != L',')
            {
                FREE_ARRAY(array);
                return NULL;
            }

            (*data)++;
        }

        // Only here if we ran out of data
        FREE_ARRAY(array);
        return NULL;
    }

    // Ran out of possibilites, it's bad!
    else
    {
        return NULL;
    }
}
开发者ID:kg4lod,项目名称:Neuro-Sand-Cube,代码行数:101,代码来源:JSONValue.cpp

示例7: website_search

const char* WebModelUnified::website_search(const char* req){
    JSONObject root;
    JSONArray jsarray;
    Connection* conn = connect();
    Query query = conn->query();

    string reqstr(req);
    string reqstr_spaced = replaceChar(reqstr, '+', ' ');
    vector<string> splittedstr;
    split(splittedstr, reqstr_spaced, boost::algorithm::is_any_of(" "));

    int titleForce = 10;
    int descriptionForce = 1;
    int urlForce = 3;

    query << "SELECT * , ";
    //Occurences total
    for(size_t i1 = 0; i1 < splittedstr.size(); i1++)
    {
        string s = splittedstr[i1];
        if(i1 != 0){
            query << " + ";
        }

        query << "((" <<
          titleForce << " * (char_length(title) - char_length(replace(title,'" << s << "',''))) + " <<
          descriptionForce << " * (char_length(description) - char_length(replace(description,'" << s << "',''))) + " <<
          urlForce << " * (char_length(url) - char_length(replace(url,'" << s << "','')))" <<
        ") / char_length('" << s << "'))";
    }
    query << " as Occurances " << " FROM website ";

    //Where clause
    for(size_t i1 = 0; i1 < splittedstr.size(); i1++)
    {
        string s = splittedstr[i1];
        if(i1 == 0) {
            query << "WHERE ";
        } else {
            query << "OR ";
        }
        query << "(url LIKE '%" << s << "%' or title LIKE '%" << s << "%' or description LIKE '%" << s << "%') ";
    }

    query << " ORDER BY " << "Occurances desc, title ASC ";

    StoreQueryResult ares = query.store();
    unsigned int numrow = ares.num_rows();

    for(unsigned int i = 0; i < numrow; i++)
    {
        JSONObject result;

        result[L"title"] = new JSONValue(wchartFromChar(ares[i]["title"]));
        result[L"description"] = new JSONValue(wchartFromChar(ares[i]["description"]));
        result[L"url"] = new JSONValue(wchartFromChar(ares[i]["url"]));
        JSONValue* resultVal = new JSONValue(result);

        jsarray.push_back(resultVal);
    }

    root[L"results"] = new JSONValue(jsarray);

    JSONValue* jvalue = new JSONValue(root);

    const char* returnStr = fromWString(jvalue->Stringify());
    delete jvalue;
    return returnStr;
}
开发者ID:alvinmeimoun,项目名称:SUPINFO_2PJT_SupInSearch,代码行数:69,代码来源:WebModelUnified.cpp


注:本文中的JSONArray::push_back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。