如何将字符串转换为JSONObject?

问题描述 投票:0回答:1

我有一个值为[email protected].的字符串我必须将此值传递给服务器,例如:{"email":"[email protected]"}

我正在使用okhttp这样向服务器传递价值:

Map<String, String> map = new HashMap<>();
        map.put("email", email);
        new PostMethodWithProgress(login_url, map, this, new Callback()
        {
            @Override
            public void done(String reply)
            {
                try
                {
                    JSONObject object = new JSONObject(reply);

                    if (object.getString("status").equals("200"))
                    {

                        //Toast Success Message
                    }
                    else
                    {
                         //Toast Failure Message
                    }
                }
                catch (Exception e)
                {
                    Log.e("ASA", "Error is: " + e);
                }
            }
        }).execute();

我该怎么办?

android json string android-studio okhttp
1个回答
0
投票
使用Google Gson将字符串转换为模型,并将模型轻松转换为字符串ConvertModel convertModel = new Gson().fromJson(reply, ConvertModel .class);

然后您可以轻松验证

© www.soinside.com 2019 - 2024. All rights reserved.