Skip to content

There is a problem with deserialization of 2D arrays of C #4388

Answered by huqin-RM
huqin-RM asked this question in Q&A
Discussion options

You must be logged in to vote
void Dimensions(const json& j, std::vector<int> &v)
{
    int n = 0;
    json tmp;
    for(auto it : j)
    {
        n++;
        tmp = it;
    }

    if(tmp.is_array())
    {
        Dimensions(tmp, v);
    }
    v.push_back(n);
}

template<typename T>
void ProcData(const json& j, std::vector<T> &v)
{
    for(auto it : j)
    {
        if(it.is_array())
        {
            ProcData(it, v);
        }else
        {
            T tmp = it.get<T>();
            v.push_back(tmp);
        }
    }
}

template<typename T>
void PrcoArray(T value);

template<typename T>
void PrcoElement(T value, const json& j, void *c, int size) {
    std::cout << typeid(value).name() << ' ' << value << std::en…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by nlohmann
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant