As most of you are aware, our Android DataGrid has built in support for rendering JSON data. For example, you can use the following code in Java to show JSON 

/**
* Takes a grid, and an XML configuration, loads the XML configuration into the Grid.
* @param grid
* @param resource
*/
public void buildGrid(FlexDataGrid grid, Integer resource) {
            grid.delegate = this;
            BufferedReader reader = new BufferedReader(new InputStreamReader(this.getResources().openRawResource(resource)));
            StringBuilder builder = new StringBuilder();
            String aux = "";
            try {
                  while ((aux = reader.readLine()) != null) {
                        builder.append(aux);
                  }
            } catch (IOException e) {
                  throw new RuntimeException(e);
            } 

            String text = builder.toString();
            flexDataGrid.buildFromXml(text);
      }

 

      /**
       * Parses json data and passes it to the grid to display
       * @param grid
       * @param resource
       */
      public void loadJsonData(FlexDataGrid grid, Integer resource) {
            BufferedReader jsonReader = new BufferedReader(new InputStreamReader(
                        this.getResources().openRawResource(resource)));
            StringBuilder jsonBuilder = new StringBuilder();
            try {
                  for (String line = null; (line = jsonReader.readLine()) != null;) {
                       jsonBuilder.append(line).append("\n");
                  }
            } catch (IOException e) {
                  throw new RuntimeException(e);
            }

 

            // Parse Json
            this.flexDataGrid.setDataProviderJson(jsonBuilder.toString());
      }

 

How would you do the same in c# Xamarin? Well, code is surprising similar:

[Activity (Label = "AndroidApp", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        int count = 1;
        FlexDataGrid flexDataGrid;

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button> (Resource.Id.myButton);
            
            button.Click += delegate {
                button.Text = string.Format ("{0} clicks!", count++);
            };

            flexDataGrid = FindViewById<FlexDataGrid> (Resource.Id.flexDataGrid1);

            LoadJsonData(flexDataGrid, Resource.Raw.flxsdatamocknesteddata);
        
        } 
        public void LoadJsonData(FlexDataGrid grid, int resource)
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(this
                .Resources.OpenRawResource(resource)));
            StringBuilder builder = new StringBuilder();
            string aux = "";
            try {
                while ((aux = reader.ReadLine()) != null) {
                    builder.Append(aux);
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            string text = builder.ToString();
            grid.SetDataProviderJson (builder.ToString ());
        }
    }

 

Attached is a sample (you will need to place your copy of the bindings dll in it).

AndroidApp.zip (87.06 kb)