本文整理汇总了C++中CVariant::toJsonValue方法的典型用法代码示例。如果您正苦于以下问题:C++ CVariant::toJsonValue方法的具体用法?C++ CVariant::toJsonValue怎么用?C++ CVariant::toJsonValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CVariant
的用法示例。
在下文中一共展示了CVariant::toJsonValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Announce
void CTCPServer::Announce(EAnnouncementFlag flag, const char *sender, const char *message, const CVariant &data)
{
Value root;
root["jsonrpc"] = "2.0";
root["method"] = "Announcement";
root["params"]["sender"] = sender;
root["params"]["message"] = message;
if (!data.isNull())
data.toJsonValue(root["params"]["data"]);
StyledWriter writer;
std::string str = writer.write(root);
for (unsigned int i = 0; i < m_connections.size(); i++)
{
{
CSingleLock lock (m_connections[i].m_critSection);
if ((m_connections[i].GetAnnouncementFlags() & flag) == 0)
continue;
}
unsigned int sent = 0;
do
{
CSingleLock lock (m_connections[i].m_critSection);
sent += send(m_connections[i].m_socket, str.c_str(), str.size() - sent, sent);
} while (sent < str.size());
}
}
示例2: FillDetails
void CFileItemHandler::FillDetails(ISerializable* info, CFileItemPtr item, const Value& fields, Value &result)
{
if (info == NULL || fields.size() == 0)
return;
CVariant data;
info->Serialize(data);
Value serialization;
data.toJsonValue(serialization);
for (unsigned int i = 0; i < fields.size(); i++)
{
CStdString field = fields[i].asString();
if (item)
{
if (item->IsAlbum() && item->HasProperty("album_" + field))
{
if (field == "rating")
result[field] = item->GetPropertyInt("album_rating");
else if (field == "label")
result["album_label"] = item->GetProperty("album_label");
else
result[field] = item->GetProperty("album_" + field);
continue;
}
if (item->HasProperty("artist_" + field))
{
result[field] = item->GetProperty("artist_" + field);
continue;
}
if (field == "fanart")
{
CStdString cachedFanArt = item->GetCachedFanart();
if (!cachedFanArt.IsEmpty())
{
result["fanart"] = cachedFanArt.c_str();
}
continue;
}
}
if (serialization.isMember(field) && !result.isMember(field))
result[field] = serialization[field];
}
}