ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Geometry Namespace / MultipointBuilderEx Class / FromJson Method
JSON string representation of the Multipoint.
Example

In This Topic
    FromJson Method (MultipointBuilderEx)
    In This Topic
    Creates a new instance of a Multipoint class from a JSON representation.
    Syntax
    public static Multipoint FromJson( 
       string jsonString
    )
    Public Shared Function FromJson( _
       ByVal jsonString As String _
    ) As Multipoint

    Parameters

    jsonString
    JSON string representation of the Multipoint.

    Return Value

    Exceptions
    ExceptionDescription
    The jsonString is empty or null.
    The JSON string is invalid or does not represent a Multipoint string.
    Example
    Import and Export Geometries to JSON
    // MapPoint
    string inputString = 
      "{\"x\":1,\"y\":2,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}";
    Geometry geometry = GeometryEngine.Instance.ImportFromJson(
      JsonImportFlags.JsonImportDefaults, inputString);
    
    MapPoint importPoint = geometry as MapPoint;
    // importPoint = 1, 2
    // importPoint.SpatialReference.WKid = 4326
    
    // use the MapPointBuilderEx convenience method
    MapPoint importPoint2 = MapPointBuilderEx.FromJson(inputString);
    // importPoint2 = 1, 2
    // impointPoint2.SpatialReference.Wkid = 4326
    
    string outputString = GeometryEngine.Instance.ExportToJson(
      JsonExportFlags.JsonExportDefaults, importPoint);
    // outputString =
    //   "{\"x\":1,\"y\":2,\"spatialReference\":{\"wkid\":4326,\"latestWkid\":4326}}"
    
    string outputString2 = importPoint.ToJson();
    
    inputString = 
      "{\"spatialReference\":{\"wkid\":4326},\"z\":3,\"m\":4,\"x\":1,\"y\":2}";
    importPoint = GeometryEngine.Instance.ImportFromJson(
      JsonImportFlags.JsonImportDefaults, inputString) as MapPoint;
    // importPoint.HasM = true
    // importPoint.HasZ = true
    // importPoint.X = 1
    // importPoint.Y = 2
    // importPoint.M = 4
    // importPoint.Z = 3
    
    importPoint2 = MapPointBuilderEx.FromJson(inputString);
    
    // export to json - skip spatial reference
    outputString = GeometryEngine.Instance.ExportToJson(
                  JsonExportFlags.JsonExportSkipCRS, importPoint);
    // outputString = "{\"x\":1,\"y\":2,\"z\":3,\"m\":4}"
    
    // export from mappoint, skipping the sr - same as GeometryEngine.Instance.ExportToJson w JsonExportFlags.JsonExportSkipCRS
    outputString2 = importPoint.ToJson(true);
    
    //
    // Multipoint
    //
    List<Coordinate2D> coords = new List<Coordinate2D>()
    {
      new Coordinate2D(100, 200),
      new Coordinate2D(201, 300),
      new Coordinate2D(301, 400),
      new Coordinate2D(401, 500)
    };
    
    Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(
      coords, SpatialReferences.WebMercator);
    
    inputString = 
      "{\"points\":[[100,200],[201,300],[301,400],[401,500]],\"spatialReference\":{\"wkid\":3857}}";
    Multipoint importMultipoint = 
      GeometryEngine.Instance.ImportFromJson(
             JsonImportFlags.JsonImportDefaults, inputString) as Multipoint;
    // importMultipoint.IsEqual(multipoint) = true
    
    ReadOnlyPointCollection points = importMultipoint.Points;
    // points.Count = 4
    // points[0] = 100, 200
    // points[1] = 201, 300
    // points[2] = 301, 400
    // points[3] = 401, 500
    
    // use the MultipointbuilderEx convenience method
    Multipoint importMultipoint2 = MultipointBuilderEx.FromJson(inputString);
    // importMultipoint2.IsEqual(multipoint) = true
    
    // export to json
    outputString = GeometryEngine.Instance.ExportToJson(
                    JsonExportFlags.JsonExportDefaults, multipoint);
    // outputString = inputString
    
    // or use the multipoint itself
    outputString2 = multipoint.ToJson();
    
    //
    // Polyline
    //
    Polyline polyline = PolylineBuilderEx.CreatePolyline(
                             coords, SpatialReferences.WebMercator);
    
    // export without the spatial reference
    outputString = GeometryEngine.Instance.ExportToJson(
                            JsonExportFlags.JsonExportSkipCRS, polyline);
    // import
    geometry = GeometryEngine.Instance.ImportFromJson(
                 JsonImportFlags.JsonImportDefaults, outputString);
    Polyline importPolyline = geometry as Polyline;
    // importPolyline.SpatialReference = null
    
    
    points = importPolyline.Points;
    // points.Count = 4
    // points[0] = 100, 200
    // points[1] = 201, 300
    // points[2] = 301, 400
    // points[3] = 401, 500
    
    // use the polylineBuilderEx convenience method 
    Polyline importPolyline2 = PolylineBuilderEx.FromJson(outputString);
    // importPolyline2 = importPolyline
    
    outputString2 = importPolyline2.ToJson();
    // outputString2 = outputString
    
    //
    // Polygon
    //
    Polygon polygon = PolygonBuilderEx.CreatePolygon(
                                  coords, SpatialReferences.WebMercator);
    
    // export without the spatial reference
    outputString = GeometryEngine.Instance.ExportToJson(
                              JsonExportFlags.JsonExportSkipCRS, polygon);
    // import
    geometry = GeometryEngine.Instance.ImportFromJson(
                         JsonImportFlags.JsonImportDefaults, outputString);
    
    Polygon importPolygon = geometry as Polygon;
    // importPolygon.SpatialReference = null
    points = importPolygon.Points;
    // points.Count = 5
    
    // polygonBuilderEx convenience method
    Polygon importPolyon2 = PolygonBuilderEx.FromJson(outputString);
    // importPolygon2 = importPolygon
    
    // export from the polygon
    outputString2 = importPolyon2.ToJson(true);
    
    // Empty polygon
    polygon = PolygonBuilderEx.CreatePolygon(SpatialReferences.WebMercator);
    outputString = GeometryEngine.Instance.ExportToJson(
                                   JsonExportFlags.JsonExportDefaults, polygon);
    importPolygon = GeometryEngine.Instance.ImportFromJson(
                        JsonImportFlags.JsonImportDefaults, outputString) as Polygon;
    
    // importPolygon.IsEmpty = true
    // importPolygon.SpatialReference.Wkid = 3857
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also