Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7517939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:36:31+00:00 2026-05-30T01:36:31+00:00

I am trying to read JSON objects using the QScriptValue class in Qt and

  • 0

I am trying to read JSON objects using the QScriptValue class in Qt and I’ve noticed that when iterating over an array I always get an extra element at the end.

Let’s say I have a string named value like this:

QString value = “{\”identifier\”:\”testID\”,
\”params\”:[{\”field\”:\”filed1:\”,
\”datatype\”:\”integer\”,\”fieldend\”:\” \”},{\”field\”:\”field2:
\”,\”datatype\”:\”integer\”,\”fieldend\”:\” \”}]}”;

My code for iteration looks like this:

QScriptValue sc;
QScriptEngine engine;
sc = engine.evaluate("("+value+")");

if(sc.isValid())
{
    if(sc.property("params").isArray())
    {
        QScriptValueIterator it(sc.property("params"));

        while(it.hasNext())
        {
            it.next();

            qDebug()<< "field:" << it.value().property("field").toString();
            qDebug()<< "datatype:" << it.value().property("datatype").toString();
            qDebug()<< "fieldend:" << it.value().property("fieldend").toString();
            qDebug()<< "--------------";
        }

    }
}

The output results with an extra element that has empty values:

field:  "field1:"
datatype:  "integer"
fieldend:  " "
--------------
field:  "field2: "
datatype:  "integer"
fieldend:  " "
--------------
field:  ""
datatype:  ""
fieldend:  ""
--------------

I read the documentation of QScriptValueIterator and it says:

The next() advances the iterator. The name(), value() and flags() functions return the name, value and flags of the last item that was
jumped over

So I changed my iteration accordingly:

while(it.hasNext())
{
    it.next();
    qDebug() << it.name() << " : " << it.value().toString();
    qDebug()<< "--------------";
}

But I get something that I did not expect:

"0"  :  "[object Object]"
--------------
"1"  :  "[object Object]"
--------------
"length"  :  "2"
--------------

Can anyone point out what am I doing wrong here?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:36:32+00:00Added an answer on May 30, 2026 at 1:36 am

    I faced the same issue and I added this line after the it.next(); line:
    if (it.flags() & QScriptValue::SkipInEnumeration) continue;
    You can find more info about it here:
    http://developer.qt.nokia.com/doc/qt-4.8/qscriptvalueiterator.html#details

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON object that I am trying to read using Python but
I'm trying to get Jquery to read a json file, But unfortunately I can
I am trying to read the following json object using the json-framework and obj-C
I'm trying to read some JSON data from the Tumblr API. I'm using the
I am trying to read certain values from a json string in php, I
I'm trying to return json content read from MySQL server. This is supposed to
Trying to read an RSS and select information using Linq but can't seem to
I'm trying to read a .doc file into a database so that I can
I've got a JSON value that has been converted from a JavaScript object using
I'm just learning json. I'm trying to create an array of object Messages, The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.