Что нового

[Данные, строки] Разборка файла .json Достаем переменные

igorit

Новичок
Сообщения
25
Репутация
0
Всем привет!
Уверен что тема уже подымалась, но поиск отказывается работать, выдает сообщение "запрос должен быть длиннее 2-х символов...".
Если тема - дубль, то дайте ссылку на решение.

Есть программа OpenHardwareMonitor, которая в WEB serwer выгружает .json файл с данными о системе:
{"id": 0, "Text": "Sensor", "Children": [{"id": 1, "Text": "IGOR-ПК", "Children": [{"id": 2, "Text": "MSI 760GM-P21(FX) (MS-7641)", "Children": [{"id": 3, "Text": "Fintek F71869A", "Children": [{"id": 4, "Text": "Voltages", "Children": [{"id": 5, "Text": "VCC3V", "Children": [], "Min": "3,168 V", "Value": "3,216 V", "Max": "3,312 V", "ImageURL": "images/transparent.png"}, {"id": 6, "Text": "CPU VCore", "Children": [], "Min": "0,840 V", "Value": "1,312 V", "Max": "1,384 V", "ImageURL": "images/transparent.png"}, {"id": 7, "Text": "Voltage #3", "Children": [], "Min": "0,000 V", "Value": "0,000 V", "Max": "0,000 V", "ImageURL": "images/transparent.png"}, {"id": 8, "Text": "Voltage #4", "Children": [], "Min": "0,000 V", "Value": "0,000 V", "Max": "0,000 V", "ImageURL": "images/transparent.png"}, {"id": 9, "Text": "Voltage #5", "Children": [], "Min": "0,000 V", "Value": "0,000 V", "Max": "0,000 V", "ImageURL": "images/transparent.png"}, {"id": 10, "Text": "Voltage #6", "Children": [], "Min": "0,848 V", "Value": "0,848 V", "Max": "0,864 V", "ImageURL": "images/transparent.png"}, {"id": 11, "Text": "Voltage #7", "Children": [], "Min": "1,056 V", "Value": "1,072 V", "Max": "1,096 V", "ImageURL": "images/transparent.png"}, {"id": 12, "Text": "VSB3V", "Children": [], "Min": "3,216 V", "Value": "3,232 V", "Max": "3,248 V", "ImageURL": "images/transparent.png"}, {"id": 13, "Text": "VBat", "Children": [], "Min": "3,232 V", "Value": "3,264 V", "Max": "3,264 V", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/voltage.png"}, {"id": 14, "Text": "Temperatures", "Children": [{"id": 15, "Text": "Temperature #1", "Children": [], "Min": "42,0 °C", "Value": "43,0 °C", "Max": "46,0 °C", "ImageURL": "images/transparent.png"}, {"id": 16, "Text": "Temperature #2", "Children": [], "Min": "57,0 °C", "Value": "59,0 °C", "Max": "63,0 °C", "ImageURL": "images/transparent.png"}, {"id": 17, "Text": "Temperature #3", "Children": [], "Min": "36,0 °C", "Value": "38,0 °C", "Max": "38,0 °C", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/temperature.png"}, {"id": 18, "Text": "Fans", "Children": [{"id": 19, "Text": "Fan #1", "Children": [], "Min": "2196 RPM", "Value": "2196 RPM", "Max": "3632 RPM", "ImageURL": "images/transparent.png"}, {"id": 20, "Text": "Fan #2", "Children": [], "Min": "966 RPM", "Value": "966 RPM", "Max": "1877 RPM", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/fan.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/chip.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/mainboard.png"}, {"id": 21, "Text": "AMD FX-6100", "Children": [{"id": 22, "Text": "Clocks", "Children": [{"id": 23, "Text": "Bus Speed", "Children": [], "Min": "200 MHz", "Value": "200 MHz", "Max": "200 MHz", "ImageURL": "images/transparent.png"}, {"id": 24, "Text": "CPU Core #1", "Children": [], "Min": "1400 MHz", "Value": "3600 MHz", "Max": "3900 MHz", "ImageURL": "images/transparent.png"}, {"id": 25, "Text": "CPU Core #2", "Children": [], "Min": "1400 MHz", "Value": "3600 MHz", "Max": "3900 MHz", "ImageURL": "images/transparent.png"}, {"id": 26, "Text": "CPU Core #3", "Children": [], "Min": "1400 MHz", "Value": "3300 MHz", "Max": "3900 MHz", "ImageURL": "images/transparent.png"}, {"id": 27, "Text": "CPU Core #4", "Children": [], "Min": "1400 MHz", "Value": "3300 MHz", "Max": "3900 MHz", "ImageURL": "images/transparent.png"}, {"id": 28, "Text": "CPU Core #5", "Children": [], "Min": "1400 MHz", "Value": "3300 MHz", "Max": "3900 MHz", "ImageURL": "images/transparent.png"}, {"id": 29, "Text": "CPU Core #6", "Children": [], "Min": "1400 MHz", "Value": "3600 MHz", "Max": "3900 MHz", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/clock.png"}, {"id": 30, "Text": "Temperatures", "Children": [{"id": 31, "Text": "Core #1 - #6", "Children": [], "Min": "38,4 °C", "Value": "48,0 °C", "Max": "62,5 °C", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/temperature.png"}, {"id": 32, "Text": "Load", "Children": [{"id": 33, "Text": "CPU Total", "Children": [], "Min": "1,0 %", "Value": "28,3 %", "Max": "53,8 %", "ImageURL": "images/transparent.png"}, {"id": 34, "Text": "CPU Core #1", "Children": [], "Min": "0,0 %", "Value": "47,7 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 35, "Text": "CPU Core #2", "Children": [], "Min": "0,0 %", "Value": "37,9 %", "Max": "64,2 %", "ImageURL": "images/transparent.png"}, {"id": 36, "Text": "CPU Core #3", "Children": [], "Min": "0,0 %", "Value": "44,6 %", "Max": "83,1 %", "ImageURL": "images/transparent.png"}, {"id": 37, "Text": "CPU Core #4", "Children": [], "Min": "0,0 %", "Value": "6,1 %", "Max": "75,4 %", "ImageURL": "images/transparent.png"}, {"id": 38, "Text": "CPU Core #5", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "61,5 %", "ImageURL": "images/transparent.png"}, {"id": 39, "Text": "CPU Core #6", "Children": [], "Min": "0,0 %", "Value": "33,8 %", "Max": "44,6 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/load.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/cpu.png"}, {"id": 40, "Text": "Generic Memory", "Children": [{"id": 41, "Text": "Load", "Children": [{"id": 42, "Text": "Memory", "Children": [], "Min": "68,5 %", "Value": "77,5 %", "Max": "79,0 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/load.png"}, {"id": 43, "Text": "Data", "Children": [{"id": 44, "Text": "Used Memory", "Children": [], "Min": "5,5 GB", "Value": "6,2 GB", "Max": "6,3 GB", "ImageURL": "images/transparent.png"}, {"id": 45, "Text": "Available Memory", "Children": [], "Min": "1,7 GB", "Value": "1,8 GB", "Max": "2,5 GB", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/power.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/ram.png"}, {"id": 46, "Text": "NVIDIA GeForce GT 630", "Children": [{"id": 47, "Text": "Clocks", "Children": [{"id": 48, "Text": "GPU Core", "Children": [], "Min": "0 MHz", "Value": "405 MHz", "Max": "810 MHz", "ImageURL": "images/transparent.png"}, {"id": 49, "Text": "GPU Memory", "Children": [], "Min": "405 MHz", "Value": "405 MHz", "Max": "500 MHz", "ImageURL": "images/transparent.png"}, {"id": 50, "Text": "GPU Shader", "Children": [], "Min": "0 MHz", "Value": "810 MHz", "Max": "1620 MHz", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/clock.png"}, {"id": 51, "Text": "Temperatures", "Children": [{"id": 52, "Text": "GPU Core", "Children": [], "Min": "41,0 °C", "Value": "43,0 °C", "Max": "49,0 °C", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/temperature.png"}, {"id": 53, "Text": "Load", "Children": [{"id": 54, "Text": "GPU Core", "Children": [], "Min": "0,0 %", "Value": "6,0 %", "Max": "44,0 %", "ImageURL": "images/transparent.png"}, {"id": 55, "Text": "GPU Memory Controller", "Children": [], "Min": "0,0 %", "Value": "8,0 %", "Max": "35,0 %", "ImageURL": "images/transparent.png"}, {"id": 56, "Text": "GPU Video Engine", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "0,0 %", "ImageURL": "images/transparent.png"}, {"id": 57, "Text": "GPU Memory", "Children": [], "Min": "10,3 %", "Value": "11,4 %", "Max": "13,7 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/load.png"}, {"id": 58, "Text": "Controls", "Children": [{"id": 59, "Text": "GPU Fan", "Children": [], "Min": "52,0 %", "Value": "52,0 %", "Max": "52,0 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/control.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/nvidia.png"}, {"id": 60, "Text": "Generic Hard Disk", "Children": [{"id": 61, "Text": "Load", "Children": [{"id": 62, "Text": "Used Space", "Children": [], "Min": "88,4 %", "Value": "88,4 %", "Max": "88,4 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/load.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/hdd.png"}, {"id": 63, "Text": "BIWIN SSD", "Children": [{"id": 64, "Text": "Temperatures", "Children": [{"id": 65, "Text": "Temperature", "Children": [], "Min": "40,0 °C", "Value": "42,0 °C", "Max": "56,0 °C", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/temperature.png"}, {"id": 66, "Text": "Load", "Children": [{"id": 67, "Text": "Used Space", "Children": [], "Min": "89,7 %", "Value": "89,8 %", "Max": "89,8 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/load.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/hdd.png"}, {"id": 68, "Text": "TOSHIBA DT01ACA100", "Children": [{"id": 69, "Text": "Temperatures", "Children": [{"id": 70, "Text": "Temperature", "Children": [], "Min": "35,0 °C", "Value": "35,0 °C", "Max": "36,0 °C", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/temperature.png"}, {"id": 71, "Text": "Load", "Children": [{"id": 72, "Text": "Used Space", "Children": [], "Min": "93,8 %", "Value": "93,8 %", "Max": "93,8 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/load.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/hdd.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/computer.png"}], "Min": "Min", "Value": "Value", "Max": "Max", "ImageURL": ""}
Вопрос: Как правильно доставать данные? На пример, температура процессора лежит в ветке:
IGOR-ПК -> MSI 760GM-P21(FX) (MS-7641) -> AMD FX-6100 -> Temperatures -> Core #1 - #6 -> Value -> 48,0 °C
Как это правильно доставать? Нашел в сети такой пример:

Код:
#include <Inet.au3>
#include <json.au3>
$URL = "moneroexplorer.com/search?value=48prJSgB3bzFrypv9i7ce6LhSpsFj7vLEiKhJHBE4grZDyYPVg1SY2r5aQmx98BHfT4FkuDe53YwG1XqgBcjJojxJtBUj98+"
$data = _INetGetSource($URL)
$object = json_decode($data)
Local $i = 0

While 1
    $product_id = json_get($object, '[' & $i & '].')
    If @error Then ExitLoop
    If $product_id = "xmr" Then
        $volume_USD = json_get($object, '[' & $i & '].volume_USD')
        ConsoleWrite('$volume_USD = ' & $volume_USD & @CRLF )
    EndIf
    $i += 1
WEnd


Но ругается на json_get и json_decode - таких функций в JSON.au3 нет!
Получить-то .json e меня получается, делаю так:
Код:
$Url = "http://" & IniRead("Settings.ini", "Settings", "ohwm_ip","") & ":" & IniRead("Settings.ini", "Settings", "ohwm_port","") & "/data.json"
$line = BinaryToString(InetRead($Url))

А вот как с него вытянуть данные - не понятно. В общем, нужна ваша помощь, а то все что ни нахожу - не по теме :(
 

sngr

AutoIT Гуру
Сообщения
1,010
Репутация
408
Код:
$file=ClipGet()
$str=StringRegExpReplace($file,'(?s).*?Core #1 - #6[^{}]+"?Value"?:\s*"?([^"]+)"?.*','\1')
MsgBox(32,'',$str)
 
Автор
I

igorit

Новичок
Сообщения
25
Репутация
0
Спасибо, работает!
Единственный вопрос: как в этом выражении вместо Core #1 - #6 поставить AMD FX-6100

P.S. подскажите, где можно почитать о регулярных выражениях, а то я в этом ничего не понимаю
 
Верх