Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.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
Iphone 无法转换Nsarray';将对象转换为字符串_Iphone_Nsstring_Nsarray - Fatal编程技术网

Iphone 无法转换Nsarray';将对象转换为字符串

Iphone 无法转换Nsarray';将对象转换为字符串,iphone,nsstring,nsarray,Iphone,Nsstring,Nsarray,我试图将数组对象转换为字符串,但它仍然返回对象的地址。 它正在返回-0x5e1e370 但是应该返回一些字符串值 NSMutableArray *arrStudents = [pillboxDb getStudentRecords]; NSString *strHow = [arrStudents objectAtIndex:0]; NSLog(@"%@",strHow); 下面是getStudentRecords的代码 +(NSMutableArray*)getStudentRecords{

我试图将数组对象转换为字符串,但它仍然返回对象的地址。 它正在返回-0x5e1e370 但是应该返回一些字符串值

NSMutableArray *arrStudents = [pillboxDb getStudentRecords];
NSString *strHow = [arrStudents objectAtIndex:0];
NSLog(@"%@",strHow);
下面是getStudentRecords的代码

+(NSMutableArray*)getStudentRecords{

NSArray *arrDocPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *strDestPath = [NSString stringWithFormat:@"%@/samplepillbox1.sqlite",[arrDocPath objectAtIndex:0]];
NSMutableArray *arrStudents = [[NSMutableArray alloc]init];
sqlite3 *db;
if(sqlite3_open([strDestPath UTF8String], &db)==SQLITE_OK)
{

    NSString *query = @"select * from doctor_master";
    void* v;
    char* err_msg;
    sqlite3_stmt *studentStmt;

    if(sqlite3_prepare_v2(db, [query UTF8String], -1, &studentStmt, &err_msg)==SQLITE_OK)
    {
        while (sqlite3_step(studentStmt)==SQLITE_ROW) {

            int sno = sqlite3_column_int(studentStmt, 0);
            NSString *sname = [NSString stringWithUTF8String: sqlite3_column_text(studentStmt, 1)];
            //float marks = sqlite3_column_double(studentStmt, 2);

            pillbox *st = [[pillbox alloc]init];
            st.Din = sno;
            st.Name = sname;

            [arrStudents addObject:st];
        }

    }

}
return arrStudents;
}试试这个:

NSString *strHow = [[arrStudents objectAtIndex:0] stringValue] ;
试试这个:

NSString *strHow = [[arrStudents objectAtIndex:0] stringValue] ;

可能您的返回对象不是字符串对象。试一试

NSLog(@“%@”,学生)


它将显示对象类型,然后使用该对象关联字符串。可能您的返回对象不是字符串对象。试一试

NSLog(@“%@”,学生)

它将向您显示对象类型,然后使用该对象关联字符串

您的自定义pillBox类(顺便说一句,编码约定为名称pillBox)使用标准NSObject描述方法:

description返回一个字符串,该字符串表示 接收班

返回值表示接收数据内容的字符串 班级

讨论调试器的print object命令调用此方法 生成对象的文本描述

NSObject对该方法的实现只是打印 班级

替代说明以提供所需的值。或者,创建一个提供所需字符串的stringValue方法。

您的自定义pillBox类(顺便说一句,编码约定为名称pillBox)正在使用标准NSObject描述方法:

NSString *str = [arrStudents ObjectAtIndex:0];
description返回一个字符串,该字符串表示 接收班

返回值表示接收数据内容的字符串 班级

讨论调试器的print object命令调用此方法 生成对象的文本描述

NSObject对该方法的实现只是打印 班级

替代说明以提供所需的值。或者,创建一个提供所需字符串的stringValue方法。

尝试以下操作:

NSString *str = [arrStudents ObjectAtIndex:0];
NSMutableArray *arrStudents = [pillboxDb getStudentRecords];
pillbox *st = [arrStudents objectAtIndex:0];
NSLog(@"%@ , %d", st.Name,st.Din);
试试这个:

NSMutableArray *arrStudents = [pillboxDb getStudentRecords];
pillbox *st = [arrStudents objectAtIndex:0];
NSLog(@"%@ , %d", st.Name,st.Din);

您正在将pillbox类的对象添加到数组中。因此,您必须首先访问pillbox对象,如

for(int i=0;i<[array count];i++)
{
pillbox *pill=[array objectAtIndex:i];

NSLog(@"%@  %@",pillbox.Name,pillbox.Din);
}

for(int i=0;i您正在将pillbox类的对象添加到数组中。因此您必须首先访问pillbox对象,如

for(int i=0;i<[array count];i++)
{
pillbox *pill=[array objectAtIndex:i];

NSLog(@"%@  %@",pillbox.Name,pillbox.Din);
}

for(int i=0;iis it CoreData对象?是否确定数组中填充了
NSString
对象?请执行此操作以验证:
NSLog(@“%@,[[arrsudents objectAtIndex:0]class]);
如何填充“pillboxDb”数组?在nsstring之前显示代码您只需检查您的arrstudents是否有任何对象?在其中使用nslog。伙计们,请检查更新的代码是否为CoreData对象?您确定数组中填充了
nsstring
对象吗?请执行此操作以验证:
nslog(@“%@,[[arrstudents ObjectatinIndex:0]类])
如何填充“pillboxDb”数组?在nsstring之前显示代码您只需检查您的学生是否有任何对象?在那里使用nslog。伙计们,请检查更新后的代码,它显示如下..“”、“”、“”、“”、“”、“”您是否有任何类名pillBox?这就是重点。数组将返回您添加到其中的对象。您添加了pillBox对象,并试图将其作为字符串获取,但不允许使用。请使用pillBox*objStd=[arrStudents objecAtIndex:i];它将返回一个pillbox对象,并使用pillbox属性检索数据。或者,当您将对象添加到数组时,将字符串对象添加到数组。它的显示方式如下..“”、“”、“”、“”、“”您是否有任何类名pillBox?这就是重点。数组将返回您添加到其中的对象。您添加了pillBox对象,并试图将其作为字符串获取,但不允许使用。请使用pillBox*objStd=[arrStudents objecAtIndex:i];它将返回一个pillbox对象,并使用pillbox属性检索数据。或在向数组添加对象时向数组添加字符串对象