iOS: How to build a table from a JSON Query? - iphone

I got a JSON response with a lot of data.
(e.g.: Private Messages).
How to display them into a table?
I mean in C#.net I normaly would have a class (PM) with a lot of Properties (sender, reciever, subject, text) and make a database-query (here JSON) and fill it in a list of my class (List pmList = new pmLIst();).
How to do it in Objective C for iPhone?

Have a look at SBJson. The TweetStream example project shows how to fetch data over an HTTP connection and parse it. If the data contains a list of objects you'll find those in an NSArray in your parsed data; at that point it's simply a matter of using a UITableView to display the data.

Have a look at restkit. It's a nice framework for parsing JSON and putting it into the right structure. The examples provided there should get you started.

Related

What is the best way to escape HTML on ExtJS application generally?

I am developing a web application using ExtJS to build GUI and communicate with server via RESTful web-service (the returned data is formatted as JSON objects).
Now I am having problems when processing with data which contains HTML tags, Javascript codes inside; because when I set those values to Ext forms, labels, input fields, they are affected by those syntaxes.
I used this function to load data from model object to form:
form.loadRecord(model);
I have found a solution to escape HTML and JS: using
field.setValue(Ext.util.Format.htmlDecode(data));
but I think that is not a good solution for whole application, because the developers must do so much things: review all input fields, labels, and put that snippet to them. And after all, that is not a beautiful way to build a fast, robust and maintainable application.
So, could you please help me solution so that it can be modified at one place, and affects to the rest. Can I override the setValue/ setLabel of AbstractComponent? Or should I encode the data before rendering them? And how to decode those data?
(P/S: I uses Grails framework on the server-side)
Thank you so much.
If you're using Ext.XTemplate, you can escape html in fields like this:
var tpl = new Ext.XTemplate(
'<p>My Field: {myField:htmlEncode}</p>'
);
Everything depends on your use case, but what I do is - escape all HTML code on server side, so that there are no 'forgotten' places by mistake. That of course creates problems, when these data need to be loaded in form fields, because they are escaped.
The easiest solution is to override setValue for all form fields and use Extjs htmlDecode function, which will revert these values back to normal.
Ext.override(Ext.form.field.Base, {
setValue: function(val) {
val = Ext.util.Format.htmlDecode(val);
return this.callParent([val]);
}
});
This link has a excellent answer by jack.slocum :
https://www.sencha.com/forum/showthread.php?13913
grid.on('validateedit', function(e){
e.value = Ext.util.Format.stripTags(e.value);
});
Util method Ext.util.Format.stripTags() removes all the html/script tags.

Creating Sample Data in Blend Expressions

I been watching TechDays 2010 Understanding MVVM and at one point he talks about blend and creating sample data but instead of generating it in blend he makes the data in C# code.
I am wondering if you create sample data(from sample class,new sample data and etc) does it save it somewhere in the project(ie I give my project to someone else will they see the same data in blend when they load up the project)? Can you switch from sample data and live data easily?
Sample data is just an xaml (not just xml) file defining your object graph that is marked with the build types DesignData or DesignDataWithDesignTimeCreatableTypes. The docs are sparse on MSDN, but this document about its use in the Silverlight designer is essentially the same in any xaml designer in 2012.
There is no "live data" when using these types of samples. All the values are set in the xaml file. You can't change the data for, say, a particular text box within the designer. Nor can you easily switch between different samples.
There are two ways to create the sample data--you can build it by hand (if you know your types and if you are comfortable writing xaml), or you can spin up a simple console application, build your object graph, then use the XamlServices class to serialize your graph to a string (or just rewrite to drop it to a stream instead). Here's some C# pseudocode that may or may not work as written:
public string Serialize(object toSerialize)
{
var sb = new StringBuilder();
var writer = XmlWriter.Create(sb);
XamlServices.Save(writer, toSerialize);
writer.Flush();
writer.Close();
return sb.ToString();
}
You just create a new file, give it an .xaml extension, drop the result in that file, save it to your solution, and set its Build Action to DesignData (the designer mocks the structure of your types) or DesignTimeDataWithDesignTimeCreatableTypes (the latter if your graph can be deserialized with XamlServices, doesn't throw any exceptions when used in the designer, etc).

Sending MMS on iPhone using CoreTelephony

I am interested in sending an MMS within a private application on the iPhone. A lot of the information I need is proprietary, and therefore I can't find it anywhere. Basically, I'm looking for the proper way to construct a CTMessage and encode it for MMS, and then sending it via one of the overloaded sendMMS functions. Thanks in advance.
For those interested: here is what I managed to dig up (&/OR piece together myself).
For every MMS, a CTMessage is allocated & initialized. addRecipient/setRecipient is called to do just that.
For each data/text section a CTMessagePart is built with its data and corresponding datatype, and then added to the CTMessage's items array. The first item in each MMS items array is always a CTMessagePart containing a SMIL-formatted layout that the recipient interprets to display the message. Each CTMessagePart following the first is in the order that it is referenced from the SMIL data.
Each (unmodifiied) iPhone has an instance of CTMessageCenter running, with the id sharedMessageCenter. Calling sharedMessageCenter's sendMMS, giving the id of the CTMessage you just created will automate the rest of the process. Essentially, the CTMessage is encoded using the CTMmsEncoder into an MMS-PDU hex string. (Not to sure of the correct name for it, hah). Anyways, sharedMessageCenter's send method will then send the (encoded) MMS to your provider's MMSC.
That pretty much sums it up, and should give anyone looking to head down that path a good place to start depending on what they're doing. I can do my best to answer any questions.

How to find difference between two XML documents

I want to compare two XML documents to find and show where is the difference
like diff utility in XCode.
I can retrieve and parse xml code using NSXMLParser in basic level,
and can tell 'they are not exactly same'
but I don't know how to tell 'where and which'.
Is there any open-source based library for this?
Thanks in advance.
Try following link
XML Documents
also try this

xml paeser for iphone app

i have a xml file on a server that look for example like this one:
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
</breakfast_menu>
i need xml parser that will parse it and enter each one of them to a class that for examle will called food(and have 4 parameters : name,price,.....).
and finally to create an array of the classes that he create.there is built xml parser that do it?
Here are some sources on the topic:
Navigating XML from Objective-C
How do I parse an NSString containing XML in Objective-C?
Objective C: Parsing an XML file
Parsing XML in Cocoa
Parsing XML in objective-c
For learning to parse xml, look at the links Brandon provided. Your requirement to build an array of classes from xml is something you'll need to create yourself.
A suggestion I have for you is instead of creating classes, just put the data into a NSMutableArray. The array will contain NSDictionary objects for food sub-items.