ArcGIS Runtime SDK for WPF - Library Reference
FromJson(String) Method
See Also  Example
ESRI.ArcGIS.Client.FeatureService Namespace > FeatureLayerInfo Class : FromJson(String) Method

json
The JSON to deserialize to FeatureLayerInfo.
Deserializes the JSON string to FeatureLayerInfo.

Syntax

Visual Basic (Declaration) 
Public Shared Function FromJson( _
   ByVal json As String _
) As FeatureLayerInfo
C# 
public static FeatureLayerInfo FromJson( 
   string json
)

Remarks

The FeatureLayerInfo.FromJson Method is a Shared/static function which means that you do not use the new keyword to instantiate it as an object.

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

If you do not pass a JSON string generated from a FeatureLayerInfo object to the FeatureLayerInfo.FromJson Method, you will get back an Unhandled Exception unless you write error handling for it. If you trap for the any error messages for the Shared/static FeatureLayerInfo.FromJson Method, its message will be similar to the following: "System.ArgumentException: Invalid JSON primitive".

Example error message when passing invalid JSON to the FeatureLayerInfo.FromJson Method.

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

Parameters

json
The JSON to deserialize to FeatureLayerInfo.

Return Value

The deserialized FeatureLayerInfo.

Example

How to use:

Click the 'Get JSON' button to obtain the JSON ASCII text for a FeatureLayer. Then modify the JSON string syntax (see the yellow highlighted area in the screen shot) in the TextBox and click the 'Modify Dynamic Layer' button to change the rendering of the 'Dynamic Layer' (a special type of ArcGISDynamicMapServiceLayer) in the Map. The FeatureLayerInfo.FromJson Method is used to construct a FeatureLayerInfo object from the JSON. Some of the Properties of the FeatureLayerInfo object are used to change the rendering of the 'Dynamic Layer'. Rendering of 'Dynamic Layers' requires having ArcGIS Server 10.1 and higher.

IMPORTANT NOTE: While it is possible to construct a 'Dynamic Layer' using parts of the FeatureLayerInfo object, this is not the most common practice. You should review the API Documentation in the ArcGISDynamicMapServiceLayer Class for the topic of 'Dynamic Layers' that have links to best practices examples. This example code is mainly to show that you can construct a FeatureLayerInfo object from raw JSON. In this very targeted example where it just so happens that the FeatureLayerInfo object created from a FeatureLayer was a sub-layer of the ArcGISDynamicMapServiceLayer in the Map. The user is supposed to know EXACTLY what parts of the JSON syntax that can be modified to render the symbology of the 'Dynamic Layer' differently. In the case of this example the following specific JSON text was modified:
FROM: esriSMSCircle TO: esriSMSCross
FROM: [255,255,115,255] TO: [0,0,0,255]
The net effect was to change the symbology from yellow filled circles to black crosses.

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.

Using the FeatureLayerInfo.FromJson Method to alter the rendering of a 'Dynamic Layer'.

XAMLCopy Code
<Grid x:Name="LayoutRoot">
  
  <!-- Add a Map Control. Zoom to the South-Western United States. -->
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="0,180,0,0" Name="Map1" 
        VerticalAlignment="Top" Height="408" Width="167" Extent="-13468458,3546553,-12238506,4578324">
  
    <!--Add a backdrop ArcGISTiledMapServiceLayer. -->
    <esri:ArcGISTiledMapServiceLayer ID="myArcGISTiledMapServiceLayer" 
          Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
    
    <!-- Add an ArcGISDynamicMapServiceLayer. -->
    <esri:ArcGISDynamicMapServiceLayer ID="myArcGISDynamicMapServiceLayer"
          Url="http://servicesbeta4.esri.com/arcgis/rest/services/USA/MapServer" />
    
  </esri:Map>
  
  <!-- Add a TextBox to display the JSON of a FeatureLayer. The text is modifiable to change the rendering of
  a DynamicLayer. -->
  <TextBox Height="410" HorizontalAlignment="Left" Margin="173,178,0,0" Name="TextBox1"
           VerticalAlignment="Top" Width="615" TextWrapping="Wrap"/>
    
  <!-- Add a Button to get the JSON from a FeatureLayer as a FeatureLayerInfo object. NOTE: the FeatureLayer chosen 
  is actually one of the sub-layers that comprises the ArcGISDynamicMapServiceLayer in the Map.-->
  <Button Content="Get JSON" Height="23" HorizontalAlignment="Left" Margin="173,151,0,0" 
          Name="Button_GetJson" VerticalAlignment="Top" Width="116" Click="Button_GetJson_Click" />
    
  <!-- Add a Button that reads the JSON ASCII text in the TextBox and generates a 'Dynamic Layer' that re-renders the 
  symbology of the ArcGISDynamicMapServiceLayer. -->
  <Button Content="Modify Dynamic Layer" Height="23" HorizontalAlignment="left" Margin="295,151,0,0" 
          Name="Button3" VerticalAlignment="Top" Width="493" Click="Button_ModifyDynamicLayer_Click" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="145" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="653" 
   TextWrapping="Wrap" Text="Click the 'Get JSON' button to obtain the JSON ASCII text for a FeatureLayer. 
   Then modify the JSON string syntax (see the yellow highlighted area in the screen shot) in the TextBox 
   and click the 'Modify Dynamic Layer' button to change the rendering of the 'Dynamic Layer' (a special type 
   of ArcGISDynamicMapServiceLayer) in the Map. The FeatureLayerInfo.FromJson Method is used to construct a 
   FeatureLayerInfo object from the JSON. Some of the Properties of the FeatureLayerInfo object are used to 
   change the rendering of the 'Dynamic Layer'. Rendering of 'Dynamic Layers' requires having ArcGIS Server 
   10.1 and higher." />
      
</Grid>
C#Copy Code
private void Button_GetJson_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // Create a FeatureLayer. NOTE: This FeatureLayer is actually one of the sub-layers of the 
  // ArcGISDynamicMapServiceLayer that is already in the Map.
  ESRI.ArcGIS.Client.FeatureLayer myFeatureLayer = new ESRI.ArcGIS.Client.FeatureLayer();
  myFeatureLayer.Url = "http://servicesbeta4.esri.com/arcgis/rest/services/USA/MapServer/0";
  myFeatureLayer.ID = "egdb.DBADMIN.USCities";
  
  // Wire up an Initialized Event Handler for the FeatureLayer.
  myFeatureLayer.Initialized += myFeatureLayer_Initialized;
  
  // Call the FeatureLayer.Initialize Method which will create the FeatureLayer using an asynchronous call
  // to ArcGIS Sever. NOTE: See how the FeatureLayer does not need to be added to the Map in order to have
  // the Initialized Event called.
  myFeatureLayer.Initialize();
}
            
private void myFeatureLayer_Initialized(object sender, EventArgs e)
{
  // Get the FeatureLayer.
  ESRI.ArcGIS.Client.FeatureLayer myFeatureLayer = (ESRI.ArcGIS.Client.FeatureLayer)sender;
  
  // Get the FeatureLayerInfo object.
  ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo myFeatureLayerInfo = myFeatureLayer.LayerInfo;
  
  // Display the JSON ASCII text of the FeatureLayerInfo object in the TextBox.
  TextBox1.Text = myFeatureLayerInfo.ToJson();
}
            
private void Button_ModifyDynamicLayer_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // IMPORTANT NOTE: While it is possible to construct a 'Dynamic Layer' using parts of the FeatureLayerInfo object, this is not
  // the most common practice. You should review the API Documentation in the ArcGISDynamicMapServiceLayer Class for the topic of 
  // 'Dynamic Layers' that have links to best practices examples. This example code is mainly to show that you can construct a 
  // FeatureLayerInfo object from raw JSON. In this very targeted example where it just so happens that the FeatureLayerInfo
  // object created from a FeatureLayer was a sub-layer of the ArcGISDynamicMapServiceLayer in the Map. The user is supposed to 
  // know EXACTLY what parts of the JSON syntax that can be modified to render the symbology of the 'Dynamic Layer' differently. 
  // In the case of this example the following specific JSON text was modified:
  // FROM: esriSMSCircle TO: esriSMSCross
  // FROM: [255,255,115,255] TO: [0,0,0,255]
  // The net effect was to change the symbology from yellow filled circles to black crosses.
  
  // Get the ArcGISDynamicMapServiceLayer defined in XAML.
  ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)(Map1.Layers["myArcGISDynamicMapServiceLayer"]);
  
  // Using Dynamic Layers to change the symbology of an ArcGISDynamicMapServiceLayer is only avilable on ArcGIS Server 10.1 and higher.
  double version = myArcGISDynamicMapServiceLayer.Version;
  if (version >= 10.1)
  {
    // Create a FeatureLayerInfo object from the JSON ASCII text in the TextBox.
    ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo myFeatureLayerInfo = ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo.FromJson(TextBox1.Text);
    
    // Create a LayerInfo object and set its Properties to some of those of the FeatureLayerInfo object (***).
    ESRI.ArcGIS.Client.LayerInfo myLayerInfo = new ESRI.ArcGIS.Client.LayerInfo();
    myLayerInfo.DefaultVisibility = true;
    myLayerInfo.ID = myFeatureLayerInfo.Id; // ***
    myLayerInfo.MaxScale = myFeatureLayerInfo.MaximumScale; // ***
    myLayerInfo.MinScale = myFeatureLayerInfo.MinimumScale; // ***
    myLayerInfo.Name = myFeatureLayerInfo.Name; // ***
    myLayerInfo.SubLayerIds = null;
    
    // Create a LayerDrawingOptionsCollection object and set it to the ArcGISDynamicMapServiceLayer.LayerDrawingOptions Property.
    ESRI.ArcGIS.Client.LayerDrawingOptionsCollection myLayerDrawingOptionsCollection = new ESRI.ArcGIS.Client.LayerDrawingOptionsCollection();
    myArcGISDynamicMapServiceLayer.LayerDrawingOptions = myLayerDrawingOptionsCollection;
    
    // Create a LayerDrawingOptions object and set its Properties to some of those of the FeatureLayerInfo object (***). 
    ESRI.ArcGIS.Client.LayerDrawingOptions myLayerDrawinOptions = new ESRI.ArcGIS.Client.LayerDrawingOptions();
    myLayerDrawinOptions.LayerID = myFeatureLayerInfo.Id; // ***
    myLayerDrawinOptions.Renderer = myFeatureLayerInfo.Renderer; // ***
    
    // Apply the new settings of the Dynamic Layer and refresh the ArcGISDynamicMapServiceLayer. The Refresh Method
    // will make this client-side request to the ArcGIS Server to re-render the ArcGISDynamicMapServiceLayer using 
    // the newly defined symbology.
    myArcGISDynamicMapServiceLayer.LayerDrawingOptions.Add(myLayerDrawinOptions);
    myArcGISDynamicMapServiceLayer.Refresh();
  }
  else
  {
    // Notify the user if using a Dyanmic Layer is not possible.
    MessageBox.Show("Changing the symbology of a Dynamic Layer not possible. Upgrade to ArcGIS Server 10.1 or higher.");
  }
}
VB.NETCopy Code
Private Sub Button_GetJson_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' Create a FeatureLayer. NOTE: This FeatureLayer is actually one of the sub-layers of the 
  ' ArcGISDynamicMapServiceLayer that is already in the Map.
  Dim myFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = New ESRI.ArcGIS.Client.FeatureLayer
  myFeatureLayer.Url = "http://servicesbeta4.esri.com/arcgis/rest/services/USA/MapServer/0"
  myFeatureLayer.ID = "egdb.DBADMIN.USCities"
  
  ' Wire up an Initialized Event Handler for the FeatureLayer.
  AddHandler myFeatureLayer.Initialized, AddressOf myFeatureLayer_Initialized
  
  ' Call the FeatureLayer.Initialize Method which will create the FeatureLayer using an asynchronous call
  ' to ArcGIS Sever. NOTE: See how the FeatureLayer does not need to be added to the Map in order to have
  ' the Initialized Event called.
  myFeatureLayer.Initialize()
  
End Sub
            
Private Sub myFeatureLayer_Initialized(sender As Object, e As EventArgs)
  
  ' Get the FeatureLayer.
  Dim myFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = sender
  
  ' Get the FeatureLayerInfo object.
  Dim myFeatureLayerInfo As ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo = myFeatureLayer.LayerInfo
  
  ' Display the JSON ASCII text of the FeatureLayerInfo object in the TextBox.
  TextBox1.Text = myFeatureLayerInfo.ToJson
  
End Sub
            
Private Sub Button_ModifyDynamicLayer_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' IMPORTANT NOTE: While it is possible to construct a 'Dynamic Layer' using parts of the FeatureLayerInfo object, this is not
  ' the most common practice. You should review the API Documentation in the ArcGISDynamicMapServiceLayer Class for the topic of 
  ' 'Dynamic Layers' that have links to best practices examples. This example code is mainly to show that you can construct a 
  ' FeatureLayerInfo object from raw JSON. In this very targeted example where it just so happens that the FeatureLayerInfo
  ' object created from a FeatureLayer was a sub-layer of the ArcGISDynamicMapServiceLayer in the Map. The user is supposed to 
  ' know EXACTLY what parts of the JSON syntax that can be modified to render the symbology of the 'Dynamic Layer' differently. 
  ' In the case of this example the following specific JSON text was modified:
  ' FROM: esriSMSCircle TO: esriSMSCross
  ' FROM: [255,255,115,255] TO: [0,0,0,255]
  ' The net effect was to change the symbology from yellow filled circles to black crosses.
  
  ' Get the ArcGISDynamicMapServiceLayer defined in XAML.
  Dim myArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer = CType(Map1.Layers("myArcGISDynamicMapServiceLayer"), ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)
  
  ' Using Dynamic Layers to change the symbology of an ArcGISDynamicMapServiceLayer is only avilable on ArcGIS Server 10.1 and higher.
  Dim version As Double = myArcGISDynamicMapServiceLayer.Version
  If version >= 10.1 Then
    
    ' Create a FeatureLayerInfo object from the JSON ASCII text in the TextBox.
    Dim myFeatureLayerInfo As ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo = ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo.FromJson(TextBox1.Text)
    
    ' Create a LayerInfo object and set its Properties to some of those of the FeatureLayerInfo object (***).
    Dim myLayerInfo As ESRI.ArcGIS.Client.LayerInfo = New ESRI.ArcGIS.Client.LayerInfo
    myLayerInfo.DefaultVisibility = True
    myLayerInfo.ID = myFeatureLayerInfo.Id ' ***
    myLayerInfo.MaxScale = myFeatureLayerInfo.MaximumScale ' ***
    myLayerInfo.MinScale = myFeatureLayerInfo.MinimumScale ' ***
    myLayerInfo.Name = myFeatureLayerInfo.Name ' ***
    myLayerInfo.SubLayerIds = Nothing
    
    ' Create a LayerDrawingOptionsCollection object and set it to the ArcGISDynamicMapServiceLayer.LayerDrawingOptions Property.
    Dim myLayerDrawingOptionsCollection As New ESRI.ArcGIS.Client.LayerDrawingOptionsCollection
    myArcGISDynamicMapServiceLayer.LayerDrawingOptions = myLayerDrawingOptionsCollection
    
    ' Create a LayerDrawingOptions object and set its Properties to some of those of the FeatureLayerInfo object (***). 
    Dim myLayerDrawinOptions As New ESRI.ArcGIS.Client.LayerDrawingOptions
    myLayerDrawinOptions.LayerID = myFeatureLayerInfo.Id ' ***
    myLayerDrawinOptions.Renderer = myFeatureLayerInfo.Renderer ' ***
    
    ' Apply the new settings of the Dynamic Layer and refresh the ArcGISDynamicMapServiceLayer. The Refresh Method
    ' will make this client-side request to the ArcGIS Server to re-render the ArcGISDynamicMapServiceLayer using 
    ' the newly defined symbology.
    myArcGISDynamicMapServiceLayer.LayerDrawingOptions.Add(myLayerDrawinOptions)
    myArcGISDynamicMapServiceLayer.Refresh()
    
  Else
    
    ' Notify the user if using a Dyanmic Layer is not possible.
    MessageBox.Show("Changing the symbology of a Dynamic Layer not possible. Upgrade to ArcGIS Server 10.1 or higher.")
    
  End If
End Sub

Requirements

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

See Also

© ESRI, Inc. All Rights Reserved.