Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何格式化或解析SOAP基元对象_Java_Android_Ios_Regex_Soap - Fatal编程技术网

Java 如何格式化或解析SOAP基元对象

Java 如何格式化或解析SOAP基元对象,java,android,ios,regex,soap,Java,Android,Ios,Regex,Soap,ANDROID 我在我的WSDL API中得到以下响应: a:10:{s:11:“sso_user_id”;s:6:“123345”;s:9:“firstname”;s:0:;s:8:“lastname”;s:0:;s:5:“abono”;s:0:;s:4:“hash”;s:32:“c2ff5bc4598d02160b57e2b3f28a3e0e”;s:5:“token”;s:32:“2DA9BA3BC52DB047C3DA5D91E3BD”;s:5:“login”;s:23:“sandor。f

ANDROID

我在我的WSDL API中得到以下响应:

a:10:{s:11:“sso_user_id”;s:6:“123345”;s:9:“firstname”;s:0:;s:8:“lastname”;s:0:;s:5:“abono”;s:0:;s:4:“hash”;s:32:“c2ff5bc4598d02160b57e2b3f28a3e0e”;s:5:“token”;s:32:“2DA9BA3BC52DB047C3DA5D91E3BD”;s:5:“login”;s:23:“sandor。fekete@inform.hu“s:6:”cookie“s:232:”;s:6:”访问“;a:1:{s:4:”角色;s:2:”否“}s:5:”错误;s:0:;”}

我在响应标签之间取了字符串

下面是有关响应结构的信息:

s:11:“sso用户id”- sso_user_id是长度为11个字符的密钥

s:6:“123345”-123345是长度为6个字符的sso_user_id的值

现在谁能帮我解析格式化或给REGEXP生成普通字符串或易于理解的字符串

注意:-这不是JSON字符串。


IOS代码和逻辑也非常受欢迎。

我已经设法做到了这一点:

public static void parseSOAPPrimitiveObject(String input, Object output)
        throws NumberFormatException, IllegalArgumentException,
        IllegalAccessException, InstantiationException {

    Class theClass = output.getClass();
    Field[] fields = theClass.getDeclaredFields();

    for (int i = 0; i < fields.length; i++) {
        Type type = fields[i].getType();
        fields[i].setAccessible(true);

        // detect String
        if (fields[i].getType().equals(String.class)) {
            String tag = "" + fields[i].getName() + "";
            if (input.contains(tag)) {
                String strValue = "";
                strValue = input.substring(input.indexOf(tag)
                        + tag.length() + 2);

                if (getValueLength(strValue) > 0) {
                    strValue = getValue(strValue);
                } else {
                    strValue = "";
                }

                fields[i].set(output, strValue);
            }
        }

        // detect int or Integer
        if (type.equals(Integer.TYPE) || type.equals(Integer.class)) {
            String tag = "" + fields[i].getName() + "";
            if (input.contains(tag)) {
                String strValue = "";
                strValue = input.substring(input.indexOf(tag)
                        + tag.length() + 2);
                fields[i].set(output, getValueLengthInt(strValue));
            }
        }
    }
}

public static String getValue(String substring) {

    String str = new String(substring);

    final Pattern pattern = Pattern.compile("\"(.+?)\"");
    final Matcher matcher = pattern.matcher(str);
    matcher.find();

    return matcher.group(0);
}

public static int getValueLength(String substring) {

    final Pattern pattern = Pattern.compile(":(.+?):");
    final Matcher matcher = pattern.matcher(substring);
    matcher.find();
    int count = 0;

    count = Integer.parseInt(matcher.group(1));

    return count;
}

public static int getValueLengthInt(String substring) {

    final Pattern pattern = Pattern.compile(":(.+?);");
    final Matcher matcher = pattern.matcher(substring);
    matcher.find();
    int count = 0;

    count = Integer.parseInt(matcher.group(1));

    return count;
}
要显示数据,请执行以下操作:

SSOuser ouser = getFormatedResponseData(result.toString());
String finalValues = "";                                    
finalValues = finalValues + "\n" + "fname= " + ouser.firstname;
finalValues = finalValues + "\n" + "lastname= " + ouser.lastname;
finalValues = finalValues + "\n" + "abono= " + ouser.abono;
finalValues = finalValues + "\n" + "hash= " + ouser.hash;
finalValues = finalValues + "\n" + "role= " + ouser.role;
finalValues = finalValues + "\n" + "sso_user_id= " + ouser.sso_user_id;
finalValues = finalValues + "\n" + "token= " + ouser.token;
finalValues = finalValues + "\n" + "login= " + ouser.login;
finalValues = finalValues + "\n" + "error= " + ouser.error;
// finalValues=finalValues+
// "\n"+"cookie= " + output.cookie;
final String val = finalValues;

runOnUiThread(new Runnable() {
    public void run() {
    txtValues.setText(val);}});

检查这个,下次尝试打电话,而不是张贴在fb,因为你知道我不会使用它regularly@KK_07k11A0585Thnx,但我已经使用自定义解析解决了它。但是你给的链接还是我需要的吗?我明天去看看。当我成功解析所有数据后,我将发布我的代码。由于分号用作分隔符,但在数据中没有转义,你能在“s:”上拆分数据并从那里开始工作吗?嗨@ZlatinZlatev我已经完成了解析。。。我将张贴代码。
SSOuser ouser = getFormatedResponseData(result.toString());
String finalValues = "";                                    
finalValues = finalValues + "\n" + "fname= " + ouser.firstname;
finalValues = finalValues + "\n" + "lastname= " + ouser.lastname;
finalValues = finalValues + "\n" + "abono= " + ouser.abono;
finalValues = finalValues + "\n" + "hash= " + ouser.hash;
finalValues = finalValues + "\n" + "role= " + ouser.role;
finalValues = finalValues + "\n" + "sso_user_id= " + ouser.sso_user_id;
finalValues = finalValues + "\n" + "token= " + ouser.token;
finalValues = finalValues + "\n" + "login= " + ouser.login;
finalValues = finalValues + "\n" + "error= " + ouser.error;
// finalValues=finalValues+
// "\n"+"cookie= " + output.cookie;
final String val = finalValues;

runOnUiThread(new Runnable() {
    public void run() {
    txtValues.setText(val);}});