Gozargah / Marzban-scripts

Some scripts for Marzban
83 stars 72 forks source link

refactor JSON parsing with gq #6

Closed oXIIIo closed 1 year ago

oXIIIo commented 1 year ago

Description

This PR addresses an issue in the Bash script related to marzban status command. The original code was designed to extract the "Service" and "State" fields from JSON data. However, it was throwing an error when attempting to access these fields when the JSON input was not an array, resulting in a "Cannot index string with string" error.

To resolve this issue, the code has been refactored to handle both array and non-array JSON inputs gracefully. It now checks the type of JSON input and processes it accordingly:

This modification ensures that the script works correctly with various JSON input formats, preventing errors and enhancing its overall robustness.

Changes Made

Testing

Tested the updated script with various JSON inputs, including arrays and non-arrays, to ensure that it parses the "Service" and "State" fields correctly without errors.

Related Issues

Fix: Gozargah/Marzban#549

SaintShit commented 1 year ago

thank you, you're helping us a lot!