I'm developing a format for exchanging information related to
television programs and how a provider maps their channel number to
stations.

The program that creates the files is written in perl, and creates
output that looks like this:

{
   "name" : "R&R Cable Co",
   "location" : "Roslyn",
   "DeviceTypes" : [
      "Analog",
      "L",
      "X"
   ],
   "X" : {
      "ChanData" : [
         {
            "stationid" : "16715",
            "callsign" : "TVGN",
            "url" :
"http://localhost/schedulesdirect//process.php?command=get&p1=schedule&p2=16715";,
            "channel" : "002"
         },
         {
            "stationid" : "12499",
            "callsign" : "ABCFP",
            "url" :
"http://localhost/schedulesdirect//process.php?command=get&p1=schedule&p2=12499";,
            "channel" : "003"
         },
         {
            "stationid" : "10626",
            "callsign" : "KOMO",
            "url" :
"http://localhost/schedulesdirect//process.php?command=get&p1=schedule&p2=10626";,
            "channel" : "004"
         },
         {
            "stationid" : "10518",
            "callsign" : "KING",
            "url" :
"http://localhost/schedulesdirect//process.php?command=get&p1=schedule&p2=10518";,
            "channel" : "005"
         },
<snip>
        {
            "stationid" : "11126",
            "callsign" : "FRESH",
            "url" :
"http://localhost/schedulesdirect//process.php?command=get&p1=schedule&p2=11126";,
            "channel" : "918"
         }
      ],
      "version" : "2",
      "modified" : "2012-06-12"
   },
   "L" : {
      "ChanData" : [
         {
            "stationid" : "16715",
            "callsign" : "TVGN",
            "url" :
"http://localhost/schedulesdirect//process.php?command=get&p1=schedule&p2=16715";,
            "channel" : "002"
         },
         {
            "stationid" : "52630",
            "callsign" : "KAPPDT2",
            "url" :
"http://localhost/schedulesdirect//process.php?command=get&p1=schedule&p2=52630";,
            "channel" : "003"
         },
(etc)

I wrote some C++ QT:


        QJson::Parser parser;
        bool ok;
            QVariantMap result = parser.parse(lineupdata, &ok).toMap();

            if (!ok)
            {
                printf("line %d: %s\n", parser.errorLine(),
parser.errorString().toUtf8().data());
                return false;
            }

            qDebug() << "Location: " << result["location"].toString();
            qDebug() << "Name: " << result["name"].toString();

            QVariant devtypes;

            foreach (devtypes, result["DeviceTypes"].toList())
            {
               qDebug() << "Device: " << devtypes.toString();
            }

Which gives me:

Location:  "Roslyn"
Name:  "R&R Cable Co"
Device:  "Analog"
Device:  "L"
Device:  "X"

so far, so good, and that gets me the outermost level of data.
However, I've run into more of a stumbling block as I try to dig
deeper, and I think it's because of how I'm trying to nest the
information.

I've tried various combinations of lists and maps to get deeper, but
I'm either getting null or long chains of QVariant dumps.

Can someone provide an example of code that would let me get access to
the channel information that's in the ChanInfo array and the "version"
for example?

Of course, if the data structure that I'm trying to import is too
complicated, then I can make adjustments in the perl that's creating
the output you see above.

Thanks.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QJson-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qjson-devel

Reply via email to