package com.didichuxing.doraemonkit.util;


import android.content.res.Resources;

import androidx.annotation.StringRes;

import com.didichuxing.doraemonkit.DoraemonKit;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import okhttp3.RequestBody;
import okio.Buffer;

/**
 * ================================================
 * 作    者：jint（金台）
 * 版    本：1.0
 * 创建日期：2020/3/27-15:08
 * 描    述：
 * 修订历史：
 * ================================================
 */
public class DokitUtil {

    public static String getString(@StringRes int stringId) {
        return DoraemonKit.APPLICATION.getString(stringId);
    }

    @StringRes
    public static int getStringId(String str) {
        try {
            Resources r = DoraemonKit.APPLICATION.getResources();
            return r.getIdentifier(str, "string", DoraemonKit.APPLICATION.getPackageName());
        } catch (Exception e) {
            LogHelper.e("getStringId", "getStringId===>" + str);
        }
        return -1;
    }


    public static String requestBodyToString(RequestBody requestBody) {
        try {
            Buffer buffer = new Buffer();
            requestBody.writeTo(buffer);
            return buffer.readUtf8();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 字符串对转json
     *
     * @param param
     * @return
     */
    public static String param2Json(String param) throws JSONException {
        String[] params = param.split("&");
        JSONObject jsonObject = new JSONObject();

        for (String p : params) {
            String[] ps = p.split("=");
            String key = ps[0];
            String value = ps[1];
            jsonObject.put(key, value);
        }

        return jsonObject.toString();
    }
}

@@ -1639,24 +1639,60 @@
 split(%22=%22);%0A
+            if(ps.length == 2)%7B%0A    
             
@@ -1719,24 +1719,28 @@
             
+ 
+   
 String value
@@ -1749,16 +1749,20 @@
  ps%5B1%5D;%0A
+    
         
@@ -1793,16 +1793,30 @@
 value);%0A
+            %7D%0A
         

Modify 1, 修正在转义字符串到Json时有key无value异常