gpt4 book ai didi

objective-c - 从 PHP structArray 为 Iphone 的 Objective C 解析 XMLRPC,就像在 Android 应用程序中从 Java 的 HashMap

转载 作者:搜寻专家 更新时间:2023-10-30 19:49:29 24 4
gpt4 key购买 nike

基本上需要将 java 代码转换为 objective-c,以便为 iphone 的 View Controller 做好准备。

XML-RPC PHP 代码

$structArray[] = new xmlrpcval(array(
'graffer' => new xmlrpcval($graffer),
'thumb' => new xmlrpcval($thumb),
'titletag' => new xmlrpcval($titletag),
'content' => new xmlrpcval($content),
'created' => new xmlrpcval($date_time),
'params' => new xmlrpcval($params),
'cid' => new xmlrpcval($cid),
'id' => new xmlrpcval($id)
), 'struct');
}
return new xmlrpcresp(new xmlrpcval($structArray , $xmlrpcArray));

PHP XML-RPC 响应

响应:

<methodResponse>
<params>
<param>
<value><array>
<data>
<value><struct>
<member><name>graffer</name>
<value><string>axl jordan</string></value>
</member>
<member><name>thumb</name>
<value><string></string></value>
</member>
<member><name>titletag</name>
<value><string>axl jordan New Graffer1 Member</string></value>
</member>
<member><name>content</name>
<value><string></string></value>
</member>
<member><name>created</name>
<value><string>WEEK AGO</string></value>
</member>
<member><name>params</name>
<value><string>default.jpg</string></value>
</member>
<member><name>cid</name>
<value><string>292</string></value>
</member>
<member><name>id</name>
<value><string>1985</string></value>
</member>
</struct></value>
<value><struct>
<member><name>graffer</name>
<value><string>Core</string></value>
</member>
<member><name>thumb</name>
<value><string></string></value>
</member>
<member><name>titletag</name>
<value><string>Core New Graffer1 Member</string></value>
</member>
<member><name>content</name>
<value><string></string></value>
</member>
<member><name>created</name>
<value><string>WEEK AGO</string></value>
</member>
<member><name>params</name>
<value><string>default.jpg</string></value>
</member>
<member><name>cid</name>
<value><string>291</string></value>
</member>
<member><name>id</name>
<value><string>1984</string></value>
</member>
</struct></value>
<value><struct>
<member><name>graffer</name>
<value><string>amputate</string></value>
</member>
<member><name>thumb</name>
<value><string></string></value>
</member>
<member><name>titletag</name>
<value><string>amputate New Graffer1 Member</string></value>
</member>
<member><name>content</name>
<value><string></string></value>
</member>
<member><name>created</name>
<value><string>WEEKS AGO</string></value>
</member>
<member><name>params</name>
<value><string>default.jpg</string></value>
</member>
<member><name>cid</name>
<value><string>290</string></value>
</member>
<member><name>id</name>
<value><string>1983</string></value>
</member>
</struct></value>
</data>
</array></value>
</param>
</params>
</methodResponse>


Java Android HashMap

private void MyG1Activity(Object[] results) {       
myG1Acts = new ArrayList<HashMap<String,Object>>();
Globals myGlobal = (Globals)getApplicationContext();
String TimageUrl = myGlobal.imageUrl;
HashMap<String,Object>hm = null;
for (Object o : results){
HashMap <?,?> map = (HashMap<?,?>)o;
hm = new HashMap<String,Object>();
Object graffer1 = map.get(GRAFFER);
if(graffer1 != null){
lGraffer1 = graffer1.toString();
hm.put(GRAFFER, lGraffer1);
}
Object tthumbnail = map.get(THUMB);
if(tthumbnail != null){
lThumbnail = TimageUrl + tthumbnail.toString();
bitmap = ImageManager.displayImage(lThumbnail);
hm.put(THUMB, bitmap);
}
Object ttag = map.get(TITLETAG);
if( ttag != null ){
ltag = ttag.toString();
hm.put(TITLETAG, ltag);
}
Object tcontent = map.get(CONTENT);
if( tcontent != null ){
hm.put(CONTENT, tcontent);
}
Object tCreated = map.get(CREATED);
if( tCreated != null ){
hm.put(CREATED, tCreated);
}
Object tParams = map.get(PARAMS);
if( tParams != null){
if (tParams.toString() == DEFAULT_THUMBNAIL){
lThumbnail = TimageUrl + tParams.toString();
}else{
jParams = TimageUrl + tParams.toString();
jParams = jParams.replace("Vs ", "\"/><img src=\"" + TimageUrl );
hm.put(IMAGE, jParams);
}
}
Object tcid = map.get(CID);
if( tcid != null ){
hm.put(CID, tcid);
}
Object tid = map.get(ID);
if( tid != null ){
hm.put(ID, tid);
getMoreID = Integer.valueOf(tid.toString());
}
myG1Acts.add(hm);
}

}

xcode 控制台输出

{
cid = 292;
created = "WEEK AGO";
graffer = "axl jordan";
id = 1985;
params = "default.jpg";
titletag = "axl jordan New Graffer1 Member";}
int k = 1;
for (NSDictionary *key in finalData) {
NSString *cid = [key objectForKey:@"cid"];
NSLog(@"key %d is %@",k++ ,cid);
NSString *titleTag = [key objectForKey:@"titletag"];
NSLog(@"key %d is %@",k++ ,titleTag);
}

找到我自己的答案

NSDictionary *key = [returnedPost objectAtIndex:indexPath.row];
NSString *titleTag = [key objectForKey:@"titletag"];

最佳答案

xcode 控制台输出

{
cid = 292;
created = "WEEK AGO";
graffer = "axl jordan";
id = 1985;
params = "default.jpg";
titletag = "axl jordan New Graffer1 Member";}
int k = 1;
for (NSDictionary *key in finalData) {
NSString *cid = [key objectForKey:@"cid"];
NSLog(@"key %d is %@",k++ ,cid);
NSString *titleTag = [key objectForKey:@"titletag"];
NSLog(@"key %d is %@",k++ ,titleTag);
}

找到我自己的答案

NSDictionary *key = [returnedPost objectAtIndex:indexPath.row];
NSString *titleTag = [key objectForKey:@"titletag"];

关于objective-c - 从 PHP structArray 为 Iphone 的 Objective C 解析 XMLRPC,就像在 Android 应用程序中从 Java 的 HashMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13662224/

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