0

私はこの応答を持っています:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:SurfaceElementListResponse xmlns:ns2="http://isiows.isiom.fr/schema/DmdCreation" xmlns:ns3="http://isiows.isiom.fr/schema/Error" xmlns:ns4="http://isiows.isiom.fr/schema/DmdDetail">
         <SurfaceElementListResult>
            <idSurfaceElement>9482</idSurfaceElement>
            <name>R04-</name>
            <type>NIVEAU</type>
         </SurfaceElementListResult>
         <SurfaceElementListResult>
            <idSurfaceElement>9486</idSurfaceElement>
            <name>Zone A</name>
            <type>ZONE</type>
         </SurfaceElementListResult>
      </ns2:SurfaceElementListResponse>
   </soap:Body>
</soap:Envelope>

上記の 1 つを除く他のすべての WS 応答で機能するため、各オブジェクトが NSDictionary に逆シリアル化されるのを待っています。他のレスポンスと比較すると、SOAP.m:+ (id) deserialize: (CXMLNode*) elementメソッドではステートメントに対するレスポンスがすべてNSString* type = [Soap getNodeValue:element withName:@"type"];nil を返すので、return[Soap deserializeAsDictionary:element];と続けて必要な結果を取得します。私の場合NSString* type = [Soap getNodeValue:element withName:@"type"];、ステートメントに到達すると、最初のオブジェクトに対して「NIVEAU」が返され、他のオブジェクトに対して「ZONE」が返されます。これにより、アプリケーションの実行と実行が許可されず、[Soap deserializeAsDictionary:element];解析結果として NSDictionary ではなく文字列オブジェクトが取得されます。

この問題を解決するのを手伝ってくれませんか?

4

1 に答える 1

2

// Deserialize an object as a generic object
+ (id) deserialize: (CXMLNode*) element{

    // Get the type
    NSString* type = [Soap getNodeValue:element withName:@"type"];

[Soap getNodeValue] を調べたところ、この関数の使用はかなり一般的すぎることがわかりました。フィールドの値として、フィールドの属性を取得するために使用されます。

// Gets the value of a named node from a parent node.

+ (NSString*) getNodeValue: (CXMLNode*) node withName: (NSString*) name {

    // Set up the variables
    if(node == nil || name == nil) { return nil; }
    CXMLNode* child = nil;

    // If it's an attribute get it
    if([node isKindOfClass: [CXMLElement class]])
    {
        child = [(CXMLElement*)node attributeForName: name];
        if(child != nil) {
            return [child stringValue];
        }
    }

    // Otherwise get the first element
    child = [Soap getNode: node withName: name];
    if(child != nil) {
        return [child stringValue];
    }
    return nil;
}

このケアでは、属性値のみを取得する新しいメソッドを作成しました。

// Gets the value of a node attribute
+ (NSString*) getNodeAttributeValue: (CXMLNode*) node withName: (NSString*) name{
    // Set up the variables
    if(node == nil || name == nil) { return nil; }
    CXMLNode* child = nil;

    // If it's an attribute get it
    if([node isKindOfClass: [CXMLElement class]])
    {
        child = [(CXMLElement*)node attributeForName: name];
        if(child != nil) {
            return [child stringValue];
        }
    }
    return nil;
}

それを Soap:deserialize: に置き換えました。

// Deserialize an object as a generic object
+ (id) deserialize: (CXMLNode*) element{

    // Get the type
    NSString* type = [Soap getNodeAttributeValue:element withName:@"type"];
//  NSString* type = [Soap getNodeValue:element withName:@"type"];
    if(type == nil || type.length == 0) {

そして、それは今まで私にとって完璧に機能しています。同じ状況の他の人に役立つことを願っています。

于 2012-08-20T08:00:01.463 に答える