Поиск сообщества
Показаны результаты для тегов 'tjsonobject'.
Найдено: 1 результат
-
Долго мучался отсутствием штатного средства красивого вывода JSON в текст, все что есть в комплекте, в REST к примеру, выводит убогую, не читаемую кашу. Плюнул и на написал свою функцию, на базе REST TSON.Format. function JsonPrettyPrint(AJsonValue : TJsonValue; AIndent : string = ' ') : string; var SourceContent: string; AChar: char; EOL: string; LeftIndent: string; isEOL: boolean; isInString: boolean; isInArray: boolean; isEscape: boolean; begin Result:=''; EOL:=#13#10; AIndent:= ' '; LeftIndent:=''; isEOL:=true; isInString:=false; isInArray:=false; isEscape:=false; SourceContent := AJsonValue.ToString; //This will basically display all strings as Delphi strings. Technically we should show "Json encoded" strings here. for AChar in SourceContent do begin case AChar of '{' : if not isInString and not isInArray then begin Result := Result + AChar + EOL; LeftIndent := LeftIndent + AIndent; Result := Result + LeftIndent; isEOL := true; end; ',' : if not isInString and (AChar = ',') then begin isEOL := false; if isInArray then Result := Result + AChar + ' ' else Result := Result + AChar + EOL + LeftIndent; end; '}' : if not isInString then begin Delete(LeftIndent, 1, Length(AIndent)); if not isEOL then Result := Result + EOL; Result := Result + LeftIndent + AChar; end; ':' : if not isInString and (AChar = ':') then Result := Result + AChar + ' '; else begin isEOL := false; Result := Result + AChar; end; end; isEscape := (AChar = '\') and not isEscape; if not isEscape and (AChar = '"') then isInString := not isInString; if not isEscape and (AChar = '[') then isInArray:=True; if not isEscape and (AChar = ']') then isInArray:=False; end; end; Результат налицо: { "Rig": { "Name": "node07", "Account": "3DQ9fRMVfxHaT7noy7molmuhlCI3RQkxt2y8BB", "PowerCost": [4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43, 4.43] }, "ExcavatorInstance": { "Host": "192.168.0.156", "Port": 38080, "APIToken": "asevsdrbdrtnetyjer34yb435t", "ConnectionType": "HTTP" }, "Devices": { "DeviceType": "", "UseDevices": [0, 1, 2, 3, 4] }, "Algorithms": { "cryptonight": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [32, "M=2", 876], "Speed": 1506138068.81243, "Power": 851 }, "lbry": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [95, 120, -1000], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "pascal": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "decred": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "neoscrypt": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "daggerhashimoto": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "daggerhashimoto_decred": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "daggerhashimoto_sia": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "lyra2rev2": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [95, 120, -1000], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "blake2s": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "equihash": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": ["2", "M=1", "676556"], "Speed": 1506138068.81243, "Power": 851 }, "daggerhashimoto_pascal": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "keccak": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 }, "sia": { "Enable": true, "Devices_TDP_CoreDelta_MemoryDelta": [108, 150, 500], "WorkerPerDevice": 1, "WorkerParameters": [], "Speed": 1506138068.81243, "Power": 851 } } } Конкретно в текущем случае, массивы мне нужны были в одну строку. Кому понадобиться иное - закомментируйте последние 4 строки.