Parsing Data in Xamarin Forms - c#

I would like to get the names in collection href(CustomerDemographics, Customers, Employees, Order Details) to populate a listview. I would like to know how to parse these information in Xamarin platform or C#.
I am quite new on this environment. I have experience how to parse json data in native ios with objective c, but it is the first time I see this type of data.

From the attached image it seems that you're requesting the service document of the OData service. Namely the http://host/service/ endpoint of the service. If you would like to get the content of the collections, you should append the names of the collections to the end of the service document URL, such as:
GET http://host/service/Categories
GET http://hsot/service/CustomerDemographics
The format of the response payload depends on the protocol version of the OData service. If you are talking to a OData V4 service (it actually seems a lot like you are querying the Northwind OData V4 sample service: http://services.odata.org/v4/northwind/northwind.svc/), the response payload will be in JSON format and you can use the ways that you are familiar with to parse the response.
In addition, I would recommend you go through the basic tutorial on OData.org so that you can get a better grasp of OData requests: http://www.odata.org/getting-started/basic-tutorial/

Related

Parse stdClass object in C#

I'm currently working on a client that has more features than another existing client for a game. One of the functionalities I would like to add is the ability for a user to add an IP address to their favourites and display relevant information of that server (IP, Port, Hostname, Gamemode etc.).
In order to do this I use an API which takes several parameters, such as the IP address and port. It returns some kind of string which contains the information that I need. However I'm having trouble extracting the information I want from the string. I did manage to do it, but I did it quick and dirty by using a dozen substrings to cut out the values of the parameters from the response.
Here's an example of an API call: http://monitor.sacnr.com/api/?IP=149.202.89.123&Port=7777&Action=info
Initially I thought the response was some kind of JSON string, but after some googling I found a question on Stackoverflow about stdClass. Apparently it's some kind of generic PHP class.
So my question is: how can I convert the response of the API to say JSON or XML, so I can easily parse it?
Example response:
O:8:"stdClass":18:{s:8:"ServerID";s:7:"1780392";s:2:"IP";s:14:"149.202.89.123";s:4:"Port";s:4:"7777";s:8:"Hostname";s:32:"Next Generation Roleplay (0.3.7)";s:8:"Gamemode";s:14:"NG:RP v3.0.409";s:8:"Language";s:7:"English";s:3:"Map";s:13:"NG-Gaming.net";s:10:"MaxPlayers";s:3:"500";s:7:"Players";s:3:"131";s:7:"Version";s:8:"0.3.7-R2";s:8:"Password";s:1:"0";s:4:"Time";s:5:"20:00";s:6:"WebURL";s:13:"ng-gaming.net";s:4:"Rank";s:3:"112";s:10:"AvgPlayers";s:5:"88.27";s:9:"HostedTab";s:1:"1";s:10:"LastUpdate";s:10:"1486138780";s:12:"TotalServers";s:4:"1305";}
Try using the Sharp Serialization Library.
As per their description: "Sharp Serialization Library serializes and deserializes primitives, ArrayLists and Hashtables, compatible with PHP serialize()"

how to run CURL commands using c#? [duplicate]

This question already has answers here:
C# - How to make a HTTP call
(3 answers)
Closed 7 years ago.
i want to get the data from elastic search using NEST but we are unable to write more consistent queries using nest.
so i want to write a url and get the json data from the CURL command and use it building my UI.
SO how can i do this using c#?
While it is a duplicate I wouldn't call out to another program just to hit a url.
Just use WebClient or WebRequest (difference)
curl is a linux tool to transfer data from & to servers through URLs.
elastic search is a full-text search engine with a RESTful web interface.
nest is a library that abstracts the REST api for you, if you say the abstractions do not fit your needs, you don't need to fall back to another command line program to query a REST server... if you're in a programming language that can do this easily and a lot more!
You can query REST server using C# just fine. This is the API spec:
https://github.com/elastic/elasticsearch/tree/master/rest-api-spec
You can write your own REST webclient:
Create a URL request and then submit the request using HTTP GET or
POST protocol . When the response data is returned, you must serialize
the data against a set of data contracts. As REST Services add new
functionality, these data contracts may need to be updated. A benefit of
working with JSON serialization rather than XML serialization is that
changes in the schema rarely cause issues for existing applications.
For instance, if a new property is added to the REST Services, an application that uses the old data contracts can still process a response without errors; however, the new property will not be available. To get the new property, you must update the data contracts. In order to make use of JSON serialization in .NET, use the DataContractJsonSerializer by referencing the following libraries in your project:
System.Runtime.Serialization
System.ServiceModel.Web
Source:
https://msdn.microsoft.com/en-GB/library/jj819168.aspx

Convert JSON to RSS via Web API?

I would like to create a generic Web API action that will accept a JSON URL as a parameter, then convert it to RSS. Everywhere I look I find RSS to JSON but not the other way around.
I did not want to use a 3rd party service but instead looking for a library that can do this. Any idea on how to leverage Web API to do this or should I just create a simple HTTP Handler for this?
You could implementing your own RSS or Atom custom MediaTypeFormatter. You can implement it so that the request will use this formatter when the accept header is set to application/atom+xml or application/rss+xml.
Filip has a blog describing this:
RSS & Atom MediaTypeFormatter for ASP.NET WebAPI
Superfeedr provide a feed API which does RSS to JSON conversion both when you poll feeds and when you want to be notified for changes in them.

Getting data from MS Database using Objective C?

So I've been doing research and I know that I will need to create a aspx script and run a query in aspx. Then convert the data into XML format for objective C to parse through it.
My question is can anyone elaborate a little bit more? I have little knowledge of xml and aspx.
For example example.com/test.aspx queries a user table, then I can get it to display on the browser. But what next? Convert it to xml format? Then how would my app retrieve the xml?
Thanks
Check out asp.net web api - this covers how to expose CRUD operations. The server web-api would either use ado.net to query the database directly and populate objects that then get serialized over the wire or you could use something like the entity framework or something like NHibernate to get the objects from the DB.
In iOS/Cocoa objective-c you would use the NSURLConnection to make a request to the web api server.
If the server is configured to return XML (your request sets accept header to application/xml), then in objective-c you would use NSXMLParser.
But, the more web friendly/modern approach is the http server could return json (request sets accept header to application/json) as the data and in iOS 5 and beyond, there's a JSON parser: http://www.raywenderlich.com/5492/working-with-json-in-ios-5

Server side PHP sql queries to C# app

I'm retrieving some userdata from a phpbb3 forum through scripts on the server.
My database does not allow for external login, so I have to go through some kind of script.
But, I'd like to know if there is a safe enough way to retrieve this data?
I know how to output some XML with echo statements, but I'm not sure if this is as secure as it should be?
Optimal method would be (psuedo code)
$array['user_id'] = $id;
$array['otherinfo'] = $var
return $array;
if I could somehow read this array with C#, it would be much easier, but I'm not sure how this would work with WebResonses or whatnot.
Any ideas?
You need a web service, that will output your responses in some format that you can parse with C#.
Php and C# are not interoperable, that s why you will need to create a service that you can consume these messages.
First option as I said is to create a web service, that C# code can consume. In this case, your C# code should know what to ask from your php web service, and you will respond to the request, in XML, or JSON or whatever format you want to use within your C# code to parse it.
Another option is to push the data to a web service that uses C#. You need to write a WCF/ Web service, and you can push the data to this service.
I suggest you to give your array output as xml or json. If we take xml as consideration, you can call the php file which gives xml output like this:
XDocument.Load("http://whatever.com/whatever.php");
And ofc you need to add the System.Xml.Linq header to use XDocument class. And also you can pass a hashed key, etc. from query string to validate the requested is coming from your app.

Categories

Resources