Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Does V8 has methods to parse json in c++.
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Matthias Ernst  
View profile  
 More options Jun 21 2012, 5:47 am
From: Matthias Ernst <matth...@mernst.org>
Date: Thu, 21 Jun 2012 11:47:55 +0200
Local: Thurs, Jun 21 2012 5:47 am
Subject: Re: [v8-users] Re: Does V8 has methods to parse json in c++.

On Thu, Jun 21, 2012 at 12:49 AM, Mark Essel <mes...@gmail.com> wrote:
> Just wanted to say thanks for asking this question Guilherme. I know have
> access to a straight forward json parser for my native module.
> when walking the jsonObject that results from the parsing do you loop over
> properties to find the keys of interest or is there a rapid/hashlike lookup
> available?

You're using it already: obj_handle->Get(propertyName)

> ie
> Handle<Value> parseJson(Handle<Value> jsonString) {
>     HandleScope scope;

>     Handle<Context> context = Context::GetCurrent();
>     Handle<Object> global = context->Global();

>     Handle<Object> JSON = global->Get(String::New("JSON"))->ToObject();
>     Handle<Function> JSON_parse =
> Handle<Function>::Cast(JSON->Get(String::New("parse")));

>     // return JSON.parse.apply(JSON, jsonString);
>     return scope.Close(JSON_parse->Call(JSON, 1, &jsonString));
> }

> then on the returned Handle<Value> obj

> Local<Array> propertyNames = obj->GetPropertyNames();
> for (int i=0;i < propertyNames->Length();++i) {
>     // check if propertyName matches one I'm interested in
> }

> or recursively walk the json tree
> Handle<Value> findMatchingValue(const string &key, Handle<Value> obj) {
>     HandleScope scope;
>     Handle<Value> rval;
>     Local<Array> propertyNames = obj->GetPropertyNames();
>     for (int i=0;i < propertyNames->Length();++i) {
>         String::Utf8Value name = properNames->Get(i);
>         if (name == *obj) { // check if propertyName matches one I'm
> interested in, not sure this will compile/function as desired
>             rval = currentValue;
>         }
>         // if value type is an object or has children, gotta figure how to
> do this
>             rval = findMatchingValue(key,value)
>     }
> }

> On Sunday, June 10, 2012 5:30:10 PM UTC-4, Guilherme Silva wrote:

>> Thanks everybody for your replies! I want to create a Script Manager that
>> encapsulates V8 and abstracts both js from json files ;).

> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.