Java – an effective way to parse the following strings?

I get the following response from the server as a string

value_ One = 3342342& amps; value_ Two = 4563445& amps; value_ three = 235333223

What is an effective way to parse this? Everything I can think of is very chaotic

Solution

Split '&', loop, split '='

public static Map<String,String> getQueryMap(String query)
{
    String[] params = query.split("&");
    Map<String,String> map = new HashMap<String,String>();
    for (String param : params)
    {
        String name = param.split("=")[0];
        String value = param.split("=")[1];
        map.put(name,value);
    }
    return map;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>