-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error C2338: could not find to_json() method in T's namespace #501
Comments
Could you provide a code example that triggers this error? |
(The unit tests run fine with AppVeyor, so the error message should come from code outside the library. It indicates that you tried to convert some user-defined type to |
I us it like this struct person {
std::string name;
std::string address;
int age;
};
person test {"Ned Flanders", "744 Evergreen Terrace", 60};
json j = test; use your example, but it does not work |
oh sorry,i see, i does not see the flow explain, thank you! |
No worries! |
another question,like this typedef char DateType[9];
typedef char TimeType[9];
typedef char UserIDType[16];
struct UserInfo
{
DateType TradingDay;
TimeType LoginTime;
UserIDType UserID;
} How can i convert struct UserInfo to Json? |
i don't find a way to convert c array, just convert like this in from_json function strcpy_s(obj.TradingDay,j["TradingDay"].get<std::string>().c_str());
strcpy_s(obj.LoginTime, j["LoginTime"].get<std::string>().c_str());
strcpy_s(obj.UserID,j["UserID"].get<std::string>().c_str()); but i don‘t kown if it's a reasonable way |
C-arrays are currently not supported, see #502. |
got it, thank you! |
I want to chime in and ask if this has been resolved (vs2015 x64). The following comlains as well: namespace glm
{
void to_json(json& j, const vec3& p)
{
// ...
}
void from_json(const json& j, vec3& p)
{
// ...
}
} |
What does the error message look like? What is |
Oh, how promt, nice.
glm::vec3 is a vector, wrapper for a three element float array.
https://glm.g-truc.net/0.9.2/api/a00001.html
Error is same as above:
json.hpp(1038): error C2338: could not find to_json() method in T's namespace
From: Niels Lohmann
Sent: Saturday, March 18, 2017 12:06 PM
To: nlohmann/json
Cc: Christoph ; Comment
Subject: Re: [nlohmann/json] error C2338: could not find to_json() method in T's namespace (#501)
What does the error message look like? What is vec3?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@theodelrieu Any ideas on this? |
I have stumbled upon the same issue. I found the offending code by replacing the
I was on Windows with Visual Studio 2015, which provided a helpful type name (other compilers can be less helpful in this regard). In other words, if you can't provide a descriptive error message at compile time, then please implement a run-time check with the most descriptive message that you can put together, or invoke the debugger. After all, your code will run under a debugger at least once. Thanks for providing us with this very useful library. |
I understand that the error message is not descriptive enough, I'd really like to put the real type in the message, but AFAIK, it's not possible, I am strongly opposed to transform a compile-time error to a runtime error, however I'm aware that VS2015 only shows the We could add some lines after the |
Yes, a descriptive compilation error would be a good alternative. Thanks for your attention. |
Hi I m facing this issue while sending some video data using json from my c++ addon to my node script
The Exact error I get is :
this is a function to return json for a certain input arguments. The issue is , that i get the above error when I build. where Y and U are of the type I think the error is that Template is unable to take the type unsigned char* which I trying to explicitly convert data and data1 in the first function given here. how should I tackle this. because If I comment these fields the program works fine. Please Let me know if I should convert to some other type or some other way to send this data using json. |
You need to convert them to std::string, assuming they are nul-terminated strings. |
in vs2015 compile
json.hpp(1038): error C2338: could not find to_json() method in T's namespace
The text was updated successfully, but these errors were encountered: