Results 1 to 2 of 2

Thread: Write JSON array in one line

  1. #1
    Join Date
    Feb 2016
    Posts
    13
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Write JSON array in one line

    Hello All!

    I want to write boolean array in one line of JSON file., like here
    "a": [false, true, true, false] or "a": [0, 1, 1, 0]


    I do like this:

    ...
    typedef bool my_arr[4];
    ...

    QJsonArray json_bool_arr{my_arr[0], my_arr[1], my_arr[2], my_arr[3]};
    json_book.insert("my_bool_array", json_bool_arr);




    but in output JSON file I got 4 separate lines with values :

    "my_bool_array": [
    false,
    true,
    true,
    false
    ],


    How can I solve this issue ?

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    512
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Write JSON array in one line

    Hi, you could try to replace the line feeds before writing the data to the file. If you use the toJson() methode, check QByteArray::replace().

    By the way, your typedef line looks weird in combination with your json_bool_arr variable. Are you sure that you want/need a typedef there?

    Ginsengelf

Similar Threads

  1. How to parse nested JSON Array and Object inside array
    By Radhika in forum General Programming
    Replies: 5
    Last Post: 17th December 2015, 08:42
  2. How to parse Json array give below
    By Radhika in forum Qt Programming
    Replies: 8
    Last Post: 2nd December 2015, 09:20
  3. Need suggestion for to write QString to JSON format
    By wagmare in forum Qt Programming
    Replies: 1
    Last Post: 17th September 2014, 09:16
  4. How to read and write line by line?
    By Alex Snet in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2010, 15:49
  5. How to write something in line of txt file
    By Zergi in forum Qt Programming
    Replies: 2
    Last Post: 24th December 2007, 10:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.