-2

I am trying to read the data to a string from postcodes.io using the MarkEmbling library, I can't seem to output the data to a readable string.

https://i.stack.imgur.com/ho57l.jpg

I want to output the data to a textbox which shows the town, county and region but it just shows the data as the image above. (I'm using the textbox for testing) also this is my first program.

This is just a simple front end desktop application for postcodes.io using the MarkEmbling library.

var data = textBox1.Text;
string myData = data.ToString();

var client = new PostcodesIOClient();
var result = client.Lookup(myData);

string myResult = result.ToString();

MessageBox.Show(myResult);
  • Lookup returns a PostCodeResult Object, which is already parsed: https://github.com/markembling/MarkEmbling.PostcodesIO/blob/d5814a4a3a9b195c804c9701ef7585d094f70685/MarkEmbling.PostcodesIO/Results/PostcodeResult.cs – Raphael Mayer Apr 09 '19 at 14:15
  • Yes, I've just noticed that shouldn't have been lazy and actually looked more into the documentation. –  Apr 09 '19 at 14:19
  • The question is quit unclear. You are getting a Json from postcodes.io. But what you expect is unclear. Display the Json string indented? Deseriliaze the Json into an object in order to use the value? – xdtTransform Apr 09 '19 at 14:31
  • Possible duplicate of [How to Convert JSON object to Custom C# object?](https://stackoverflow.com/questions/2246694/how-to-convert-json-object-to-custom-c-sharp-object) – xdtTransform Apr 09 '19 at 14:32
  • @OmniCodec If your question got answered, close this question by selecting an answer. – Raphael Mayer Apr 10 '19 at 08:06

3 Answers3

1

The return of Lookup is of type "PostcodeResult", which is the already processed (or as MarkEmbling uses in the library: "executed") result.

You can check the source code to see the available properties: https://github.com/markembling/MarkEmbling.PostcodesIO/blob/d5814a4a3a9b195c804c9701ef7585d094f70685/MarkEmbling.PostcodesIO/Results/PostcodeResult.cs

Raphael Mayer
  • 667
  • 6
  • 19
1

It is possible to read the data from the library with the following example.

var result = client.Lookup(myData);

string myResult = result.AdminCounty + "\n" + result.AdminDistrict + "\n" + result.Region.ToString();
0

You can convert object to string by JavaScriptSerializer and show

using System.Web.Script.Serialization;

var json = new JavaScriptSerializer().Serialize(result);
MessageBox.Show(json );
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62