Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL XML or JSON to return to Objective-C via ASP.NET

I have a question about getting Data from a SQL Database via ASP.NET and then passing the data over to Objective-C. Currently I am just using an SQL select statement to get data from the database via ASP.NET and ASP.NET returns the data like so:

<ArrayOfKeyValueOfstringPunchListCellModel84zsBx89 xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<KeyValueOfstringPunchListCellModel84zsBx89>
<Key>ORC0023</Key>
<Value xmlns:d3p1="http://schemas.datacontract.org/2004/07/LHS.Models">
</Value>
</KeyValueOfstringPunchListCellModel84zsBx89>
</ArrayOfKeyValueOfstringPunchListCellModel84zsBx89>

And then in Objective-C I am putting the data in a NSDictionary like so:

NSDictionary *punchList = [[NSDictionary alloc]initWithDictionary:[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&myError]];

Everything is working as expected here.

What I am doing now is creating a stored procedure that returns XML and have ASP.NET return the XML (everything here is completed and working as expected) The XML came out like so:

<KeyValueOfstringPunchListCellModel84zsBx89>
<Key>ORC0023</Key>
<Value>
</Value>
</KeyValueOfstringPunchListCellModel84zsBx89>
</ArrayOfKeyValueOfstringPunchListCellModel84zsBx89>

Now for you Objective-C fans, you know you can’t have XML in NSDictionary unless you use a third party item/library.

Now my question is do I have redo my stored procedure to return JSON or this there another way to go about this?

My end goal is make the process as fast as possible and the SQL query is huge and returns alot of rows.

like image 387
user979331 Avatar asked Apr 28 '16 02:04

user979331


1 Answers

You should

1) redo your stored proc and return the raw data.

2) Have asp.net handle the data formatting, since some clients might want JSON while others would prefer xml. so if you're going the JSON route, you can return JSON result from the MVC controller i.e

  public JsonResult GetData()
        {
            var temp = new {
                name = "hello world" 
            };
            return this.Json(temp)
        }

or create a web service using web api.

since you have a large result set, you should try using JSON which is less verbose than xml and thus will eat up less resources

like image 178
dfdsfdsfsdf Avatar answered Nov 14 '22 15:11

dfdsfdsfsdf