Web services with JSON Parsing - iphone

In my app Web services are created in dot net and i am consuming those and I am getting response.In that all the fields like company,type,location everything are strings and there is no problem with this..And there is one more field called Exhibit number actually it is a Integer but they are created as string only.While I am displaying this it is showing zero instead of that number.. Here is my code...
//Storing into Array
[SurveyFilesArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:[dic objectForKey:#"FileName"],#"FileName",[dic objectForKey:#"ExibhitNumber"],#"ExhibitNumber",[dic objectForKey:#"Description"],#"Description",[dic objectForKey:#"FileQuality"],#"FileQuality",nil]];
//Retrieving from Array..
NSLog(#"???%#???",[NSString stringWithFormat:#"%d",[[[SurveyFilesArray objectAtIndex:indexPath.row]objectForKey:#"ExibhitNumber"]intValue]]);
NSLog(#"%d",[[[SurveyFilesArray objectAtIndex:indexPath.row]objectForKey:#"ExibhitNumber"]intValue]);

You have typos in your code.
In the order of your code:
Ex-ib-hit-Number
Ex-hib-it-Number
These are 2 different strings.
In your example code you save it correctly written as Ex-hib-it. But you try to access it with ex-ib-hit afterwards. This cannot work.

Related

Encoding issue when retrieving text from QTableWidgetItem

I'm working on a GUI using PyQt5 and a QTableWidget containing CheckBoxes items. I populate the table with data from json file and the user can check/uncheck items.
When I want to retrieve data from my QTableWidget items, I get unexpected error due to some characters : \x19. The character in question is ’ which is well displayed elsewhere.
I don't understand the issue as my input json data is utf-8, I use python3 and when I check my data, I see no encoding issue. This error occurs only when calling text() method on QTableWidgetItem.
As I don't see any other way to retrieve data from my items, I'm quite stuck on it.
with open(filepath) as file:
self.data = json.load(file)
for key, value in self.data.items():
print(key, self.data[key])
keyword_box = QTableWidgetItem(key)
I get no error if I use key to compare with other string for example but when I want to retrieve data (no editing was performed by the user, strings didn't change)
items = self.table.selectedItems()
for item in items:
print(item.text())
I get unknown character in my console and if I try to use the value, I get a \x19 character which fails when I use it to compare with keys in my dictionary.
Could this come from a bug in QTableWidgetItem text() method ?

Getting arabic string from NSMutableArray

I trying to make an app where the user enters a text then save it to the database but before that it will be added to NSMutableArray. The thing is when I log the array, it removes the encoding and shows the text like this:
\U0662\U0664.\U0660\U0665.\U0662\U0660\U0661\U0664 \U0660\U0662:\U0663\U0662 \U0635
Can someone help me and tell me how to re-encode the text to arabic?
EDIT : the text is not showing correctly neither in the log or the interface.
Logging the array and logging the string is not the same thing and the string will display differently in the console depending on how you do it. That is, there is a difference between logging:
po yourArray
and
po [yourArray firstObject]
As long as the string displays correctly in your interface both before and after storing it in the database you should have nothing to worry about. The way the string is printed to the console when you log the contents of the array does not affect how it appears when you display it using a label in your UI.

Separate values from array

This string response i am getting from server.
2001,wooza,0420224346,J Wratt ,+61417697070,2013-55-1803-55-54.jpg,No<br />2002,wooza,0420224346,J Wratt ,+61417697070,2013-56-1803-56-17.jpg,No<br />2003,testing,9894698946,ggh hjj,9894598945,2013-11-1811-11-40.jpg,Yes<br />
I separate each record through "br" and stored it in a array.How do i access (2013-55-1803-55-54.jpg) value from array.
You can get through objectAtIndex method.
Alrenatively its better you keep the all the related data of your custom class and storing that in array.
Most of the times you will need more than one value during display. In that case, just get the object from array and show related info through object reference.
Take comma separated strings from an intended element in a different array and use NSPredicate to get the string containing .jpg in it.

PDF Table of Contents Parsing with iOS Quartz 2D

This question has been asked before, I know. However, nobody has answered it well. I'm wondering how to parse a PDF's "table of contents" on the iPhone. The docs tell me to use CGPDFDocumentGetCatalog but not how to use it. All they say is that it returns a dictionary. Also, I can't find any example code. Any suggestions?
looks like the closest thing seen on SO is Create a table of contents from a pdf file
It's basically just parsing the CGPDFDictionary called "Outline" in the CGPDFPage.
// get outline & loop through dictionary...
CGPDFDictionaryRef outlineRef;
if(CGPDFDictionaryGetDictionary(pdfDocDictionary, "Outlines", &outlineRef)) {
}
then you start with the First element and parse your way through.
CGPDFDictionaryGetDictionary(outlineRef, "First", &firstEntry)
You want to get the Title and the Destination.
NSString *outlineTitle = PSPDFStringFromPDFDict(outlineElementRef, #"Title");
CGPDFDictionaryGetObject(outlineElementRef, "Dest", &destinationRef)
The tricky thing starts with getting the correct destination, because there are (horray, PDF!) several ways to store it, plus several ways that are not defined in the PDF Reference but still out in the wild. Plus several variants that are just broken and you have to deal with it.
For example, you could get the Count of the outline dictionary using
CGPDFInteger elements;
if(CGPDFDictionaryGetInteger(outlineRef, "Count", &elements)) {
PSPDFLog(#"parsing outline: %ld elements. (Count will be ignored anyway)", (long int)elements);
}else {
PSPDFLogError(#"Error while parsing outline. No outlineRef?");
}
But note that Count sometimes is invalid due to broken PDF creation tools. See PDF as HTML. Even if it's broken, parsers will do their best to display as much data as they can. So my advice is to ignore Count and parse the dictionary anyway. (A few weeks ago I encountered a document that had Count = -10. Go figure)
I can't post the full code, as it's from my commercial PDF library PSPDFKit, and I need to make a living out of it ;) But this should get you started.

Does NSXMLParser eat blank values?

I have some XML which looks like this:
<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value><array><data>
<value><array><data>
<value><dateTime.iso8601>20100508T14:49:56</dateTime.iso8601></value>
<value><string></string></value>
<value><string>comment</string></value>
<value><string></string></value>
<value><string>Milestone milestone1 deleted</string></value>
<value><int>1</int></value>
</data></array></value>
</data></array></value>
</param>
</params>
</methodRepsonse>
NSXMLParser seems to not be giving any data back for the blank values resulting in an array with 4 items in it instead of 6.
Is there anything I can do to NSXMLParser to make it return an empty string for the blank values so that I can maintain the order of the data when it is returned?
So after whipping up a quick sample with a delegate that just prints out what's happening during parsing I don't see anything at all wrong with what's being parsed.
I suspect however that you're relying on an incorrect expectation that between calls to didStartElement... and didEndElement... you should get a foundCharacters... call with an empty string? My question is based on the way you phrased the title of your question because there's no such thing as a "blank value." Either there is a value, or there isn't.
Imagine instead your XML contained <string/> instead of the exactly equivalent <string></string>. You still get start/end notifications.
You should be creating your NSMutableString (presumably the type that you're using for your <string> elements) in didStartElement... when <string> is found, appending to that string IF foundCharacters... is called (it can get called more than once with the value in chunks), and tossing it into your array when it's done on didEndElement....
If you really want to be more robust, you'll also be wanting detect an error condition if you find the start of a new element before your string ends, assuming that it is in fact an error for you.
Not quite sure I understand your problem here. NSXMLParser would at least report the beginning and end of the elements. Would that not be enough the get them in the right order?