gpt4 book ai didi

java - 如何在java中将字符串绑定(bind)到对象

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:38:45 26 4
gpt4 key购买 nike

我有一个这种格式的字符串(来自 EBS 支付网关的响应)

key1=value1&key2=value2&key3=value3

如何在不使用 split 方法的情况下绑定(bind)到此类对象?

public class MyClass {

private String key1;
private String key2;
private String key3;
// getter and setter methods
...
}

最佳答案

尝试跟随

public class MyClass {

private String key1;
private String key2;
private String key2;

public MyClass(String k1,String k2,String k3)
{
Key1 = k1;
Key2 = k2;
Key3 = k3;
}
// getter and setter methods
...
}

同时创建类的对象

String response = "key1=value1&key2=value2&key3=value3";
String[] keys = response.split("&");
MyClass m = new MyClass(keys[0].split("=")[1],keys[1].split("=")[1],keys[2].split("=")[1])

关于java - 如何在java中将字符串绑定(bind)到对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17546904/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com