我試圖捲曲網頁,並做了一些處理,並在最後我試圖以JSON格式打印。(這實際上需要在MongoDB中輸入)bash腳本打印輸出
所以輸入(這是讀儘管捲曲)是
輸入:
brendan google engineer
stones microsoft chief_engineer
david facebook tester
的那種處理的,我的變量($名稱,$ emloyer,$名稱)分配值
我的最後命令,該命令轉換成JSON是,
echo [{\"Name\":\"$name\"},{\"Employer\":\"$employer\"},{\"dDesignation\":\"$designation\"}]
電流輸出是,
[{"Name":"brendan","Employer":"google","Designation":"engineer"}]
[{"Name":"stones","Employer":"microsoft","Designation":"chief_engineer"}]
[{"Name":"david","Employer":"facebook","Designation":"tester"}]
但是,我想在同一行中輸出由逗號和方括號中分離(不在每行)
預期輸出:
[{"Name":"brendan","Employer":"google","Designation":"engineer"},{"Name":"stones","Employer":"microsoft","Designation":"chief_engineer"},
{"Name":"david","Employer":"facebook","Designation":"tester"}]
有任何建議。
爲什麼你在意如果你生成JSON是換行符?你應該關心分析樹和文檔模型是什麼樣子 - 如果你需要關心元素之間的空白是什麼樣的,那麼你的消費者(解析你生成的代碼的人)就是做錯了。 –
......特別是,MongoDB *絕對不會在意在語法相關位置(如字符串內容)之外是否有換行符或空格。 –