f
This commit is contained in:
@@ -51,8 +51,8 @@ func ProcessQYGLJ0Q1Request(ctx context.Context, params []byte, deps *processors
|
|||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析响应中的JSON字符串
|
// 解析响应中的 JSON 字符串(使用 qyglb4c0 中的 RecursiveParse)
|
||||||
parsedResp, err := ParseJsonResponse(data)
|
parsedResp, err := RecursiveParse(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
@@ -63,42 +63,3 @@ func ProcessQYGLJ0Q1Request(ctx context.Context, params []byte, deps *processors
|
|||||||
}
|
}
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseJsonResponse 直接解析JSON响应数据
|
|
||||||
// data: 接口返回的数据
|
|
||||||
// Returns: 解析后的数据
|
|
||||||
func ParseJsonResponse(data interface{}) (interface{}, error) {
|
|
||||||
return RecursiveParse(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RecursiveParse 递归解析JSON数据
|
|
||||||
func RecursiveParse(data interface{}) (interface{}, error) {
|
|
||||||
switch v := data.(type) {
|
|
||||||
case string:
|
|
||||||
var parsed interface{}
|
|
||||||
if err := json.Unmarshal([]byte(v), &parsed); err == nil {
|
|
||||||
return RecursiveParse(parsed)
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
case map[string]interface{}:
|
|
||||||
for key, val := range v {
|
|
||||||
parsed, err := RecursiveParse(val)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
v[key] = parsed
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
case []interface{}:
|
|
||||||
for i, item := range v {
|
|
||||||
parsed, err := RecursiveParse(item)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
v[i] = parsed
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
default:
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ func ProcessQYGLUY3SRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析响应中的JSON字符串
|
// 解析响应中的 JSON 字符串(使用 qyglb4c0 中的 RecursiveParse)
|
||||||
parsedResp, err := ParseJsonResponse(data)
|
parsedResp, err := RecursiveParse(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
@@ -54,42 +54,3 @@ func ProcessQYGLUY3SRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
}
|
}
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseJsonResponse 直接解析JSON响应数据
|
|
||||||
// data: 接口返回的数据
|
|
||||||
// Returns: 解析后的数据
|
|
||||||
func ParseJsonResponse(data interface{}) (interface{}, error) {
|
|
||||||
return RecursiveParse(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RecursiveParse 递归解析JSON数据
|
|
||||||
func RecursiveParse(data interface{}) (interface{}, error) {
|
|
||||||
switch v := data.(type) {
|
|
||||||
case string:
|
|
||||||
var parsed interface{}
|
|
||||||
if err := json.Unmarshal([]byte(v), &parsed); err == nil {
|
|
||||||
return RecursiveParse(parsed)
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
case map[string]interface{}:
|
|
||||||
for key, val := range v {
|
|
||||||
parsed, err := RecursiveParse(val)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
v[key] = parsed
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
case []interface{}:
|
|
||||||
for i, item := range v {
|
|
||||||
parsed, err := RecursiveParse(item)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
v[i] = parsed
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
default:
|
|
||||||
return v, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user