0
votes

I am new to iOS, i have created entity in core data with cityName distance driverId
strainDescription strainId strainImage strainName strainTypeName vendorBusinessName vendorDriverEngagementId vendorOverallRating

of datatype NSstring, i am trying save the data in entity,expecting output

Below is my extracted JSON Object..

(
     {
    responseCode = 0;
},
    (
            {
        cityName = “mumbai”;
        distance = "2,412.3";
        driverId = 00000000076;
        strainDescription = "his is no creeper! ";
        strainId = 00000000004;
        strainImage = "www.d.net/dDocuments/StrainImages/Eyed Jamaican.jpg";
        strainName = "Eyed Jamaican";
        strainTypeName = "Body Car";
        vendorBusinessName = businessName11;
        vendorDriverEngagementId = 172;
        vendorOverallRating = "4.8";
    },
            {
        cityName = BLACKFOOT;
        distance = "2,412.3";
        driverId = 00000000073;
        strainDescription = "pain relief, anxiety";
        strainId = 00000000006;
        strainImage = "www.d.net/dDocuments/StrainImages/Abra Cadabra.jpg";
        strainName = "Abra Cada";
        strainTypeName = "Body C";
        vendorBusinessName = businessName15;
        vendorDriverEngagementId = 174;
        vendorOverallRating = "2.1";
    },

) )

i am trying save the data in entity,expecting output

Core Data Entity

cityName distance driverId strainDescription strainId….

mumbai 2,412.3 00000000076 his is no creeper! 00000000004

BLACKFOOT 2,412.3 00000000073 pain relief 0006 …..

bd *entity = [NSEntityDescription insertNewObjectForEntityForName:@“db”inManagedObjectContext:self.managedObjectContext];
if (entity!=nil){
entity.cityName= [json valueForKey:@"cityName"];
entity.distance=[json valueForKey:@"distance"];
entity.distance=[json valueForKey:@“dr”iverID];
NSError *savingError = nil;
if ([self.managedObjectContext save:&savingError]){                        
}else{
NSLog(@"Failed to save the context. Error = %@", savingError);
NSLog(@"Successfully saved the context.");
}
}else{
NSLog(@"Failed to create the doobsterdb");
}

});

1

1 Answers

0
votes

json string and i want to save in core data entity

(
    {
    responseCode = 0;
},
    (
            {
        cityName = "mumbai";
        distance = "2,412.3";
        driverId = 00000000076;
        strainDescription = "his is no creeper!";
        strainId = 00000000002;
        strainImage = "www.dbst.net/DoobsterDocuments/StrainImages/Eyed Jamaican.jpg";
        strainName = "Eyed Jamaican";
        strainTypeName = "Body Car";
        vendorBusinessName = businessName11;
        vendorDriverEngagementId = 172;
        vendorOverallRating = "4.8";
    },
            {
        cityName = BLACKFOOT;
        distance = "2,412.3";
        driverId = 00000000076;
        strainDescription = "pain relief, anxiety";
        strainId = 00000000006;
        strainImage = "www.dbst.net/dbstDocuments/StrainImages/Abra Cadabra.jpg";
        strainName = "Abra Cadabra";
        strainTypeName = "Body Car";
        vendorBusinessName = businessName15;
        vendorDriverEngagementId = 174;
        vendorOverallRating = "2.1";
    },



   )

)