Giter Club home page Giter Club logo

Comments (7)

nixzhu avatar nixzhu commented on June 26, 2024

@Edwardmark I don't have much experience with cpp, but you are passing the same doc pointer to the recursive function convertTreeNodeToJSON, is this a problem?

from yyjson.

Edwardmark avatar Edwardmark commented on June 26, 2024

@nixzhu Thanks for you reply. I want to convert a tree structure to json, so I have to use the same doc pointer. The problem is about the jsonNode or SubNode in the recursion function. I print the value, it shows when the bottom recursion end, the upper function call cannot get their value, print result is null.

from yyjson.

Edwardmark avatar Edwardmark commented on June 26, 2024

@Edwardmark I don't have much experience with cpp, but you are passing the same doc pointer to the recursive function convertTreeNodeToJSON, is this a problem?

It is not about cpp, I want to verify if the doc owns its subnode memory when calling the recursion function? And what should I do to fix the issue? Thanks .

from yyjson.

ibireme avatar ibireme commented on June 26, 2024

@Edwardmark The doc holds memory for all json values, so the recursive call seems good.

There are two string handling issues:

  1. yyjson_mut_str() doesn't take ownership of the string. If the passed string is modified or freed during use, errors like \u0000 may occur. Consider using yyjson_mut_strcpy() instead.
  2. The string returned by yyjson_mut_val_write() needs to be freed after use.

If you share the TreeNode source code, we can better understand and replicate the issue.

from yyjson.

Edwardmark avatar Edwardmark commented on June 26, 2024

@ibireme Thanks for your reply. It is the problem. I change yyjson_mut_str() to yyjson_mut_strcpy() and it worked.
And for problem2, how to free the string? Could you give me a example? Thanks.

from yyjson.

ibireme avatar ibireme commented on June 26, 2024

@ibireme Thanks for your reply. It is the problem. I change yyjson_mut_str() to yyjson_mut_strcpy() and it worked. And for problem2, how to free the string? Could you give me a example? Thanks.

Just call free(json_str).

from yyjson.

Edwardmark avatar Edwardmark commented on June 26, 2024

@ibireme Thanks.

from yyjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.