看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Win10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) VC2017 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) nlohmann/json 問題(Question): 欲利用josn 讀取一個從cline接收到的字串, 可以依據其key 讀取value , 讀取時發生錯誤 餵入的資料(Input): client傳送來的文字串 [ { "_id": "5acb0a9494eb20cde1dbe689", "index": 0, "guid": "210941f6-9151-4315-8dfe-d7e0485afb18" }, ] 預期的正確結果(Expected Output): auto keep = j_from_cbor["_id"] ; // keep = 5acb0a9494eb20cde1dbe689 錯誤結果(Wrong Output): 程式錯誤 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) https://ideone.com/vxFCgF 補充說明(Supplement): 加入第150行欲讀取時發生錯誤。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.248.167.253 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1523256414.A.543.html ※ 編輯: smartjay (60.248.167.253), 04/09/2018 14:48:42
lylu: 猜是最後右大括號後的逗點造成json parse error 04/09 16:57
smartjay: 感謝1大提醒!用json complete = json::parse(folder); 04/09 17:47
smartjay: 可以完整依key讀value 04/09 17:47
smartjay: parse 將字串(json)轉為josn物件 進行 讀取 04/09 17:48