如何使用jsoncpp传输此数据? [英] How do I use jsoncpp to transmit this data?

查看:87
本文介绍了如何使用jsoncpp传输此数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将桌面应用程序转换为客户端/服务器应用程序的客户端版本。



我需要在函数调用中使用JSON数据,例如



I am converting a desktop app to a client version of a client/server app.

I need JSON data to be used in a function call like

void ProcessData(long long Type,long long Kind, long long Shape,long long Index,Json::Value &jValue )
{
   int iState = 1;
   jValue[Type][MakeString(Kind)][Shape][MakeString(Index)] = 1;
}





其中MakeString()是一个从long long转换为string的函数。



问题是operator []报告参数类型有很多匹配。



我怎样才能绕过考虑到引入json的代码已经具有结构这一事实的众多参数类型。



如果有更好的方法来处理这个问题,我会喜欢要知道。只是函数的参数是固定的。



我尝试过:



我花了几个小时用谷歌搜索解决方案。



Where MakeString() is a function that converts from long long to string.

The problem is that the operator[] reports that there are numerous matches for the argument type.

How can I get round the numerous argument type considering the fact that the code that json is being introduced to already has a structure.

If there is a better way to handle this, I'll like to know.Its just that the parameter of the function are fixed.

What I have tried:

I have spent several hours googling for a solution.

推荐答案

如果类型转换不明确,你就会遇到奇怪的错误。最好强制执行显式类型转换,如下所示:

If the type conversion isnt clear, you run into trouble of getting strange bugs. It better to enforce the explicit type conversion like this:
[(const char*) MakeString(Index)] 



可能是字符串的自动转换是原始问题。我不喜欢这种连接的表达式,因为它使调试更难。


It could be that the automatic cast from the string is the original problem. I dont like such concatenated expressions, because it make debugging harder.

String s= MakeString(Index);
[(const cahr*) s] // use result in json 


这篇关于如何使用jsoncpp传输此数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆