2014-12-10 2 views
0

Google 서버 중 하나에 전송할 문자열을 만들어야하는데 그 과정에서 오류가 발생하기 시작했는데 문제가 무엇인지 알았지 만 해결 방법을 찾을 수 없습니다. 누구든지 아이디어가 있다면, 나는 그 (것)들을 듣기에 아주 열려있다.건물 문제 NSMutableString

다음은이 클래스를 XML 문자열로 변환하는 내 전체 메서드입니다.

- (NSData *)classToXML 
{ 
    NSMutableString *xml = [@"<JournalData xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" mutableCopy]; 
    // 150 
    if(_journalSubject.length > 150) 
     _journalSubject = [_journalSubject stringByReplacingCharactersInRange:NSMakeRange(151, _journalSubject.length - 150) withString:@""]; 
    [xml appendFormat:@"<JournalSubject>%@</JournalSubject>", _journalSubject]; 
    if(self.recipientList == nil) 
     [xml appendFormat:@"<RecipientList isNull=\"True\"/>"]; 
    else 
    { 
     [xml appendString:@"<RecipientList>"]; 
     for(CTIJournalRecipients *r in self.recipientList) 
      [xml appendString:[r classToXML]]; 
     [xml appendString:@"</RecipientList>"]; 
    } 
    [xml appendFormat:@"<JournalSysCategoryid1>%@</JournalSysCategoryid1>", _sysCategoryid1]; 
    [xml appendFormat:@"<JournalSysCategoryid2>%@</JournalSysCategoryid2>", _sysCategoryid2]; 
    [xml appendFormat:@"<Userid>%@</Userid>", _userid]; 
    [xml appendFormat:@"<Deptid>%@</Deptid>", _deptid]; 
    [xml appendFormat:@"<Activityid>%@</Activityid>", _activityid ? _activityid : @(0)]; 
    // 50 
    if(_deptDescription.length > 50) 
     _deptDescription = [_deptDescription stringByReplacingCharactersInRange:NSMakeRange(51, _deptDescription.length - 50) withString:@""]; 
    [xml appendFormat:@"<DeptDescription>%@</DeptDescription>", _deptDescription]; 
    [xml appendFormat:@"<SecLevel>%@</SecLevel>", _securityLevel]; 
    [xml appendFormat:@"<AttachedDocs>%@</AttachedDocs>", _attachedDocs]; 
    [xml appendFormat:@"<Priority>%@</Priority>", _priority]; 
    // 60 
    if(_associatedActivity.length > 60) 
     _associatedActivity = [_associatedActivity stringByReplacingCharactersInRange:NSMakeRange(61, _associatedActivity.length - 60) withString:@""]; 
    [xml appendFormat:@"<AssociatedActivity>%@</AssociatedActivity>", _associatedActivity.length > 0 ? _associatedActivity : @"No Activity"]; 
    [xml appendFormat:@"<JournalPerson>%@</JournalPerson>", _journalPerson]; 
    [xml appendFormat:@"<JournalDoc>%@</JournalDoc>", _journalDoc]; 
    [xml appendFormat:@"<JournalTransmission>%@</JournalTransmission>", _recipientList.count > 0 ? @"Y" : @"N"]; 
    [xml appendFormat:@"<JournalAssignment>%@</JournalAssignment>", _journalAssignment]; 
    [xml appendFormat:@"<JournalTag>%@</JournalTag>", _journalTag]; 
    [xml appendString:@"<JournalMemo>%@</JournalMemo>", _journalMemo]; 
    [xml appendFormat:@"<CreateUserFullname>%@</CreateUserFullname>", _createUserFullName]; 
    [xml appendFormat:@"<CreateUserID>%@</CreateUserID>", _userid]; 
    [xml appendFormat:@"<Macroid>%@</Macroid>", _macroid]; 
    [xml appendFormat:@"<sContext>%@</sContext>", [_sContext capitalizedString]]; 
    [xml appendFormat:@"<iDetail1>%@</iDetail1>", _iDetail1 ? _iDetail1 : @(0)]; 
    [xml appendFormat:@"<iDetail2>0</iDetail2>"]; 
    [xml appendFormat:@"<iDetail3>0</iDetail3>"]; 
    [xml appendFormat:@"<iDetail4>0</iDetail4>"]; 
    [xml appendFormat:@"<sConcerning>%@</sConcerning>", _sConcerning]; 
    [xml appendFormat:@"<sFaxCover>%@</sFaxCover>", _sFaxCover]; 
    [xml appendFormat:@"<bTransmit>%@</bTransmit>", _recipientList.count > 0 ? @"true" : @"false" ]; 
    // 18 
    if(_journalHeaderAccess.length > 18) 
     _journalHeaderAccess = [_journalHeaderAccess stringByReplacingCharactersInRange:NSMakeRange(19, _journalHeaderAccess.length - 18) withString:@""]; 
    [xml appendFormat:@"<JournalHeaderAccess>%@</JournalHeaderAccess>", _journalHeaderAccess.length > 0 ? _journalHeaderAccess : _sContext]; 
    [xml appendFormat:@"<vParams isNull=\"True\"></vParams>" ]; 
    [xml appendFormat:@"<DocumentList isNull=\"True\"></DocumentList>"]; 
    [xml appendFormat:@"<iJournalReplyHeaderid>%@</iJournalReplyHeaderid>", _iJournalReplyHeader]; 
    [xml appendFormat:@"<iReplyToTransmissionid>%@</iReplyToTransmissionid>", _iReplyToTransmissionid]; 
    [xml appendFormat:@"</JournalData>"]; 
    //NSString *xmlFinal = [NSString stringWithFormat:xml, [_journalMemo dataUsingEncoding:NSUTF8StringEncoding]]; 
    //CLSNSLog(@"%@", xml); 
    return xmlEncoded; 
} 

내 문제는 JournalMemo 필드 함께 나는이 문자열을 사용하는 경우 : 나는 XML로 그 메모 필드를 삽입하기 위해 여러 가지 방법을 시도하고 여기에 XML 직전의 모습입니다

n\n\n12/9/14, 11:26 PM: Someone Else wrote:\n\nTest reply please.\r\n\r\nThanks!\r\n\r\n\r\n 

을 나는 JournalMemo 토큰에 삽입 :

<JournalData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<JournalSubject>RE: Test reply please</JournalSubject> 
<RecipientList> 
    <JournalRecipients> 
     <RecipientMethod>rmTo</RecipientMethod> 
     <CommID>6711</CommID> 
     <CommTypeID>52</CommTypeID> 
     <CommName>[email protected]</CommName> 
     <PersonID>2656</PersonID> 
     <PersonName>Some Person</PersonName> 
     <PersonCategoryID>0</PersonCategoryID> 
     <PersonCategory /> 
     <PersonType /> 
     <ToType /> 
    </JournalRecipients> 
</RecipientList> 
<JournalSysCategoryid1>2000</JournalSysCategoryid1> 
<JournalSysCategoryid2>490</JournalSysCategoryid2> 
<Userid>2656</Userid> 
<Deptid>0</Deptid> 
<Activityid>0</Activityid> 
<DeptDescription>No Department Selected</DeptDescription> 
<SecLevel>1</SecLevel> 
<AttachedDocs>N</AttachedDocs> 
<Priority>NORMAL</Priority> 
<AssociatedActivity>No Activity</AssociatedActivity> 
<JournalPerson>N</JournalPerson> 
<JournalDoc>N</JournalDoc> 
<JournalTransmission>Y</JournalTransmission> 
<JournalAssignment>N</JournalAssignment> 
<JournalTag>X</JournalTag> 
<JournalMemo>%@</JournalMemo> 
<CreateUserFullname>Someone Else</CreateUserFullname> 
<CreateUserID>2676</CreateUserID> 
<Macroid>0</Macroid> 
<sContext>(null)</sContext> 
<iDetail1>0</iDetail1> 
<iDetail2>0</iDetail2> 
<iDetail3>0</iDetail3> 
<iDetail4>0</iDetail4> 
<sConcerning>(null)</sConcerning> 
<sFaxCover>Primary Cover Sheet</sFaxCover> 
<bTransmit>true</bTransmit> 
<JournalHeaderAccess>(null)</JournalHeaderAccess> 
<vParams isNull="True"></vParams> 
<DocumentList isNull="True"></DocumentList> 
<iJournalReplyHeaderid>557762</iJournalReplyHeaderid> 
<iReplyToTransmissionid>1170918</iReplyToTransmissionid> 
</JournalData> 

내가 문자열을 삽입 한 후, 이것은 XML 변수는 모습입니다 같은 :

<JournalData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<JournalSubject>RE: Test reply please</JournalSubject> 
<RecipientList> 
    <JournalRecipients> 
     <RecipientMethod>rmTo</RecipientMethod> 
     <CommID>6711</CommID> 
     <CommTypeID>52</CommTypeID> 
     <CommName>[email protected]</CommName> 
     <PersonID>2656</PersonID> 
     <PersonName>Some Person</PersonName> 
     <PersonCategoryID>0</PersonCategoryID> 
     <PersonCategory /> 
     <PersonType /> 
     <ToType /> 
    </JournalRecipients> 
</RecipientList> 
<JournalSysCategoryid1>2000</JournalSysCategoryid1> 
<JournalSysCategoryid2>490</JournalSysCategoryid2> 
<Userid>2656</Userid> 
<Deptid>0</Deptid> 
<Activityid>0</Activityid> 
<DeptDescription>No Department Selected</DeptDescription> 
<SecLevel>1</SecLevel> 
<AttachedDocs>N</AttachedDocs> 
<Priority>NORMAL</Priority> 
<AssociatedActivity>No Activity</AssociatedActivity> 
<JournalPerson>N</JournalPerson> 
<JournalDoc>N</JournalDoc> 
<JournalTransmission>Y</JournalTransmission> 
<JournalAssignment>N</JournalAssignment> 
<JournalTag>X</JournalTag> 
<JournalMemo> 


12/9/14, 11:26 PM: Someone Else wrote: 

Test reply please. 

Thanks! 

그리고이 문제를 일으키는 원인이 무엇인지, 어떻게 해결할 수 있는지 잘 모르겠습니다. 어떤 도움이라도 대단히 감사하겠습니다. \n이 문제를 일으키는

+0

나머지 XML 파일이 생성되지 않아서 메모 필드를 삽입하는 데 문제가 있습니까? – jsetting32

+0

내 게시물에 언급했듯이, 내가 알아낼 수없는 memofield에는 문제가 있습니다. – arythiafan

답변

0

answer이 내 문제를 극복 할 수있었습니다.

UTF8 인코딩과 관련된 몇 가지 문제가 있으므로이 코드를 사용하여 끝났습니다.

NSString *str = [NSString stringWithUTF8String: [_journalMemo cStringUsingEncoding: [ NSString defaultCStringEncoding ] ] ]; 
[xml appendFormat:@"<JournalMemo>%@</JournalMemo>", str]; 
0

, 당신은 그것을 탈출해야합니다

사용 :

_journalMemo = [_journalMemo stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"]; 
+0

나는 그것을 시도했지만 문자열은 여전히 ​​생성되지 않습니다. 나는 \ n과 \ r도 탈출했다. 나는 여전히 다른 아이디어에 열려 있습니다. – arythiafan