[quickjs-devel] Re: How to iterate an object in c++ code?

  • From: siney <sineysan@xxxxxxx>
  • To: <quickjs-devel@xxxxxxxxxxxxx>
  • Date: Sat, 04 Jan 2020 01:02:27 +0800

Thanks, Guido and Vladimir,

I try to use JS_GetOwnPropertyNames function, it work.

Thanks again.

在 2020/1/3 下午7:20,“Vladimir Timofeev”<quickjs-devel-bounce@xxxxxxxxxxxxx 代表 
vovkasm@xxxxxxxxx> 写入:

    Hi!
    
    Did you try to use JS_GetOwnPropertyNames?
    
    On Fri, Jan 3, 2020 at 12:16 PM sineysan <sineysan@xxxxxxx> wrote:
    >
    >
    > Thanks reply.
    >
    > I pass a JS object from js to c, how I iterate all keys from the object 
in c side?
    > I have tried to call JS_GetIterator(ctx, val), "val" is the object passed 
from script, but got an error "value is not iterable".
    >
    >
    > At 2020-01-03 16:46:20, "Guido Grassel" <guido.grassel@xxxxxxxxxx> wrote:
    >
    > Hi!
    >
    >
    >
    > If this is a string that is JSON encoded, you first need to decode the 
string to get JS objects (JSValue)  that you can then read / write from C.
    >
    > Use JS_ParseJson(..)
    >
    >
    >
    > If you already have JS objects, you need to check their type first 
(functions JS_IsNumber/String,/Object/Array), then read out (convert to C 
types) number, string, bool, Array, and Object separately.
    >
    >
    >
    > To my knowledge there is no function that would do all of this in one go.
    >
    >
    >
    > -         Guido
    >
    >
    >
    >
    >
    > From: quickjs-devel-bounce@xxxxxxxxxxxxx 
[mailto:quickjs-devel-bounce@xxxxxxxxxxxxx] On Behalf Of sineysan
    > Sent: 03 January 2020 08:34
    > To: quickjs-devel@xxxxxxxxxxxxx
    > Subject: [quickjs-devel] How to iterate an object in c++ code?
    >
    >
    >
    > Hello:
    >
    >
    >
    > I want to iterate a Json object in c++ code, how to do this? I can't find 
any API for this purpose.
    >
    >
    >
    >
    >
    >
    >
    >
    
    
    
    -- 
    Vladimir Timofeev <vovkasm@xxxxxxxxx>
    



Other related posts: