ArcGIS API for Silverlight - Library Reference
ToJson Method
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client.FeatureService Namespace > FeatureLayerInfo Class : ToJson Method

Serializes the FeatureLayerInfo to JSON.

Syntax

Visual Basic (Declaration) 
Public Function ToJson() As String
C# 
public string ToJson()

Remarks

The FeatureLayerInfo.ToJson Method is a very fast operation as it processes exclusively on the Client; no round trip to ArcGIS Server is required.

The FeatureLayerInfo.ToJson Method is useful to obtain a JSON string representation from a FeatureLayerInfo object. This then can then serve as the parameter argument for the Shared/static FeatureLayerInfo.FromJson Method.

NOTE: You should only pass JSON from FeatureLayerInfo objects into the Shared/static FeatureLayer.FromJson Method; do not use other JSON types (for example: JSON from ESRI.ArcGIS.Client.Symbols.Symbol, ESRI.ArcGIS.Client.Geometry.Geometry, etc.).

Return Value

A JSON string representation of the FeatureLayerInfo.

Example

How to use:

Click the button to display the JSON of a FeatureLayerInfo object in a MessageBox.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Displaing the JSON from a FeatureLayerInfo object.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
  
  <!-- Add a Button to display the JSON of a FeatureLayerInfo. -->
  <Button Content="Display the JSON of a FeatureLayerInfo object." Height="23" 
          HorizontalAlignment="Left" Margin="0,100,0,0" Name="Button1" VerticalAlignment="Top" Width="300" 
          Click="Button1_Click"/>
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="75" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="500" 
             TextWrapping="Wrap" Text="Click the button to display the JSON of a FeatureLayerInfo object in a MessageBox." />
  
</Grid>
C#Copy Code
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // Create a new FeatureLayer. Set it's Url and ID Properties.
  ESRI.ArcGIS.Client.FeatureLayer myFeatureLayer = new ESRI.ArcGIS.Client.FeatureLayer();
  myFeatureLayer.Url = "http://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer/0";
  myFeatureLayer.ID = "World_Transportation";
  
  // Create in in-line lambda expression for the FeatureLayer.Initialized Event. It executes after the
  // FeatureLayer Initialize Method is called.
  myFeatureLayer.Initialized += (a, b) =>
  {
    // Get the FeatureLayerInfo object from the FeatureLayer.LayerInfo Property.
    ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo myFeatureLayerInfo = myFeatureLayer.LayerInfo;
    
    // Get the Json string from the FeatureLayerInfo.Json Method.
    string theJsonString = myFeatureLayerInfo.ToJson();
    
    // Display the Json string to the user in a MessageBox.
    MessageBox.Show(theJsonString);
  };
  
  // Call the FeatureLayer.Initialize Method which will execute the in-line lambda expression.
  // NOTE: You do not need to add the FeatureLayer to a Map Control in order to execute the 
  // FeatureLayer.Initilized Event.
  myFeatureLayer.Initialize();
}
VB.NETCopy Code
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' Create a new FeatureLayer. Set it's Url and ID Properties.
  Dim myFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = New ESRI.ArcGIS.Client.FeatureLayer()
  myFeatureLayer.Url = "http://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer/0"
  myFeatureLayer.ID = "World_Transportation"
  
  ' Create in in-line lambda expression for the FeatureLayer.Initialized Event. It executes after the
  ' FeatureLayer Initialize Method is called.
  AddHandler myFeatureLayer.Initialized,
  Sub(a, b)
    
    ' Get the FeatureLayerInfo object from the FeatureLayer.LayerInfo Property.
    Dim myFeatureLayerInfo As ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo = myFeatureLayer.LayerInfo
    
    ' Get the Json string from the FeatureLayerInfo.Json Method.
    Dim theJsonString As String = myFeatureLayerInfo.ToJson()
    
    ' Display the Json string to the user in a MessageBox.
    MessageBox.Show(theJsonString)
    
  End Sub
  
  ' Call the FeatureLayer.Initialize Method which will execute the in-line lambda expression.
  ' NOTE: You do not need to add the FeatureLayer to a Map Control in order to execute the 
  ' FeatureLayer.Initilized Event.
  myFeatureLayer.Initialize()
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

© ESRI, Inc. All Rights Reserved.