Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. parse a json file

parse a json file

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 447 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ivelin
    wrote on last edited by
    #1

    Hello,

    I am trying to parse a json file in which I have data like me urls to my server.

    For the parser I am using a library called nlohmann_json.

    Now my problem is when I am trying to use the library to parse and use my config.json I am getting the following error:

    E libc++abi: terminating with uncaught exception of type nlohmann::json_abi_v3_11_3::detail::parse_error: [json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON
    

    This seems to be expected since I am not sure if I have passed my config.json to my apk build as I should have.

    As far as I am aware this should be done with qt_add_resources, but still I had no success in parsing my file.

    Here's the part of my CMakeLists.txt that I think is important

    set(PROJECT_SOURCES
            src/main.cpp
            src/AndroidService.cpp
            src/NetworkManager.cpp 
            src/StorageManager.cpp
            src/NotificationManager.cpp
            src/utility/permission.cpp
            src/utility/device.cpp
            src/services/BootService.cpp
            src/services/LocationService.cpp
            src/services/CameraService.cpp
            src/services/TrackLocationService.cpp
            src/config.json
            src/Config.cpp
            src/json.hpp
    )
    
    qt_add_executable(secureme
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
    
    set(JSON_Install OFF CACHE INTERNAL "")
    
    add_subdirectory(src/nlohmann_json)
    
    target_link_libraries(secureme PRIVATE Qt6::Gui Qt6::CorePrivate Qt6::Network Qt6::Positioning Qt6::Widgets Qt6::Multimedia Qt6::WebSockets Qt6::Concurrent Qt6::Qml nlohmann_json::nlohmann_json
    )
    
    if(ANDROID)
        set(ANDROID_TARGET_SDK_VERSION 34)
        add_android_openssl_libraries(secureme)
    
        set_property(TARGET secureme APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
                     ${CMAKE_CURRENT_SOURCE_DIR}/android)
    
                qt6_add_resources(secureme "main"
                     PREFIX
                         "/"
                     FILES
                     "qml/CustomTextField.qml"
                         "qml/Auth.qml"
                         "qml/AppStyle.qml"
                         "qml/CustomButton.qml"
                         "qml/home.qml"
                         "qml/main.qml"
                         "qml/images/logo.png"
                         "src/config.json"
                     )
    
        qt_finalize_executable(secureme)
    endif()
    

    as you can see I have both added it to my PROJECT_SOURCES and qt resources since I wasn't sure where to put it.

    Could someone help me try to figure out why do I get such an error? Where I have messed up?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you passing that file to nlohmann's library ?
      If you try to pass it the path to the QRC file, then it won't work as non Qt libraries don't know how to access such resources.
      You need to either copy the file to a temporary path or load it to a buffer and pass that further.

      Note that Qt also has JSON support.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved