本文整理汇总了C#中JsonObject.AddObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.AddObject方法的具体用法?C# JsonObject.AddObject怎么用?C# JsonObject.AddObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.AddObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToJsonObject
public JsonObject ToJsonObject()
{
JsonObject result = new JsonObject();
if (Attributes.Count > 0) {
JsonObject attributes = new JsonObject();
foreach (KeyValuePair<string, object> kvp in Attributes) {
attributes.AddObject(kvp.Key, kvp.Value);
}
result.AddJsonObject("attributes", attributes);
}
if (Geometry != null) {
result.AddJsonObject("geometry", Conversion.ToJsonObject(Geometry));
}
return result;
}
示例2: RootResHandler
private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
JsonObject infoJSON = new JsonObject();
infoJSON.AddString("name", ".Net Edit Features REST SOE");
infoJSON.AddString("description", "This SOE adds and edits features to a selected layer in the host map service. "
+ "Note that this SOE is not designed to work with map services that have features stored in SDC data format."
+ " The \"layers\" subresource returns all layers in the map service."
+ " The \"editFeature\" operation allows editing an existing feature in the layer indicated by this SOE's layerId property.\n"
+ " The \"addFeatures\" operation allows addition of a new feature to the layer indicated by this SOE's layerId property.\n"
+ " The acceptableSchema JSON below indicates the correct schema that could be used to add/edit features. This schema belongs to the layer "
+ "selected for editing by the ArcGIS Server administrator via the SOE's layerId property. This property's value can be "
+ "modified using ArcGIS Manager.");
// validation - ensure user has provided right layer id property value.
if (this.layerId > this.layerInfos.Count - 1)
{
return createErrorObject(406, "Layer Id " + this.layerId + " is invalid.", new String[] {
"Acceptable layer ids are between 0 and "
+ (layerInfos.Count - 1) + ".",
"Also ensure that the id points to a feature layer." });
}
// inform the user that edits can be done only on feature layers, if no
// feature layer corresponds to user-provided layerId
if (this.editLayerInfo == null)
{
this.editLayerInfo = this.layerInfos.get_Element(this.layerId);
if (!this.editLayerInfo.IsFeatureLayer)
{
return createErrorObject(
403,
"The layerId property of this SOE currently points to a layer (id: "
+ this.layerId
+ ") that is not a feature layer.",
new String[] {
"Only feature layers can be edited by this SOE.",
"Modify SOE's layerId property using ArcGIS Manager or ArcGIS Desktop's Service Editor." });
}
}
// Grab the fc powering the layer if its null, which means it did not get initialized in construct(), thereby
// suggesting that the layerId property value is incorrect.
if (this.fc == null)
{
// The down side of grabbing fc here is
// that a new instance of fc is created once for every request.
// Can't create fc in init(), since layerId property value for a
// particular service is not necessarily available always when init() is invoked.
this.fc = (IFeatureClass) this.mapServerDataAccess.GetDataSource(this.mapServerInfo.Name, this.layerId);
if (this.fc == null)
{
// if its still null, return error
return createErrorObject(
406,
"Incorrect layer id provided.",
new String[] { "Please provide layer id of a feature layer." });
}
}
infoJSON.AddString("Layer selected for editing", editLayerInfo.Name.ToString() + " (" + layerId + ")");
JsonObject schemaJSON = getSchemaJSON();
infoJSON.AddObject("acceptableSchema", schemaJSON);
return Encoding.UTF8.GetBytes(infoJSON.ToJson());
}
示例3: DescribeLayersHandler
private byte[] DescribeLayersHandler(NameValueCollection boundVariables,
JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
responseProperties = null;
JsonObject tResult = new JsonObject();
tResult.AddLong("AvailableLayerCount", m_ExtractableParams.Count);
JsonObject tLayersJson = new JsonObject();
foreach (ExtractionLayerConfig layer in m_ExtractableParams){
//int id = layer.LayerID;
string lyrName = layer.LayerName;
string requestParameter = layer.ParamName;
string extractionType = layer.ExtractionType.ToString();
JsonObject tLayerJson = new JsonObject();
//tLayerJson.AddLong("LayerId", id);
tLayerJson.AddString("LayerName",lyrName);
tLayerJson.AddString("LayerDescription", layer.LayerDescription);
tLayerJson.AddString("ExtractionType", extractionType);
if (layer.HasCategories)
{
IFeatureClass tLayerAsFc = (IFeatureClass)layer.LayerDataset;
string tCatName = tLayerAsFc.Fields.get_Field(layer.CategoryField).Name;
tLayerJson.AddString("CategoryField", tCatName);
}
tLayersJson.AddObject(requestParameter,tLayerJson);
}
tResult.AddObject("Extractions", tLayersJson);
byte[] tOutput = System.Text.Encoding.UTF8.GetBytes(tResult.ToJson());
return tOutput;
}
示例4: GetSpeciesExtentHandler
private byte[] GetSpeciesExtentHandler(NameValueCollection boundVariables,
JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
responseProperties = "{\"Content-Type\" : \"text/javascript\"}";
long? idnoValue; //out parameter for the ID_NO as a long
operationInput.TryGetAsLong("ID_NO", out idnoValue); //get the ID_NO parameter
IQueryFilter queryFilter = new QueryFilterClass(); //instantiate a filter for the passed species
queryFilter.WhereClause = "ID_NO='" + idnoValue + "' AND Legend<>''"; //set the where clause
IFeatureCursor featureCursor = speciesFeatureClass.Search(queryFilter, false); //get the feature cursor to the matching features
IFeature feature = null; //for iterating through the features
IGeometryCollection pGeometryCollection = new GeometryBagClass() as IGeometryCollection; //instantiate a geometry bag to get the extent
object obj = Type.Missing; //needed to add geometries to the geometry bag
while ((feature = featureCursor.NextFeature()) != null) //iterate through the matching features and add the geometries to the geometry bag
{
pGeometryCollection.AddGeometry(feature.ShapeCopy, ref obj, ref obj); //add the geometry
}
JsonObject result = new JsonObject(); //create the return json object
IEnvelope extent = (pGeometryCollection as IGeometry).Envelope; //get the extent of the geometry bag
JsonObject jsonExtent = Conversion.ToJsonObject(extent); //convert the extent to json
//TODO: Set the spatial reference for the extent in the SOE - at the moment it is set in the client code
result.AddObject("extent", jsonExtent); //write the extent to the result object
result.AddString("featureCount", pGeometryCollection.GeometryCount.ToString()); //get the number of features
return Encoding.UTF8.GetBytes(result.ToJson()); //return the json
}
示例5: ReportDomainsHandler
private byte[] ReportDomainsHandler(NameValueCollection boundVariables,
JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
responseProperties = null;
string strSDELayerName;
bool found = operationInput.TryGetString("SDEName", out strSDELayerName);
if (!found || string.IsNullOrEmpty(strSDELayerName))
throw new ArgumentNullException("SDEName");
IStandaloneTable pStandAloneTable = GetLayerfromSDE(strSDELayerName);
IField pField;
Dictionary<string, Dictionary<string, string>> dicResults = new Dictionary<string, Dictionary<string, string>>();
Dictionary<string, string> dicDomainValues;
for (int i = 0; i <= pStandAloneTable.Table.Fields.FieldCount - 1; i++)
{
pField = pStandAloneTable.Table.Fields.get_Field(i);
IDomain pDomain;
pDomain = pField.Domain;
if (pDomain != null)
{
//PrintDomainValues(pField.Name, pDomain.DomainID);
dicDomainValues = new Dictionary<string, string>();
ICodedValueDomain pCodedValueDomain;
pCodedValueDomain = pDomain as ICodedValueDomain;
if (pCodedValueDomain != null)
{
//Console.WriteLine(pField.Name + ": " + pDomain.DomainID.ToString());
//Console.WriteLine("------------------------------------------");
for (int k = 0; k <= pCodedValueDomain.CodeCount - 1; k++)
{
string name = pCodedValueDomain.get_Value(k).ToString();
string value = pCodedValueDomain.get_Name(k).ToString();
dicDomainValues.Add(name, value);
//Console.WriteLine(name + ", " + value);
}
//Console.WriteLine("------------------------------------------");
//Console.WriteLine(Environment.NewLine);
dicResults.Add(pField.Name, dicDomainValues);
}
}
}
JsonObject result = new JsonObject();
result.AddObject("Domains", dicResults);
//result.AddString("SDEName", strSDELayerName);
return Encoding.UTF8.GetBytes(result.ToJson());
}
示例6: MakeDomainOptionsHandler
private byte[] MakeDomainOptionsHandler(NameValueCollection boundVariables,
JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
responseProperties = null;
string strSDELayerName;
bool found = operationInput.TryGetString("SDEName", out strSDELayerName);
if (!found || string.IsNullOrEmpty(strSDELayerName))
throw new ArgumentNullException("SDEName");
string strFieldName;
found = operationInput.TryGetString("fieldname", out strFieldName);
if (!found || string.IsNullOrEmpty(strSDELayerName))
throw new ArgumentNullException("fieldname");
IStandaloneTable pStandAloneTable = GetLayerfromSDE(strSDELayerName);
IField pField;
Dictionary<string, string> dicDomainValues;
option opt = new option();
opt.Result = "OK";
List<Dictionary<string, string>> lstDics = new List<Dictionary<string, string>>();
int iFieldIndex = pStandAloneTable.Table.Fields.FindField(strFieldName);
if (iFieldIndex != -1)
{
pField = pStandAloneTable.Table.Fields.get_Field(iFieldIndex);
IDomain pDomain;
pDomain = pField.Domain;
if (pDomain != null)
{
ICodedValueDomain pCodedValueDomain;
pCodedValueDomain = pDomain as ICodedValueDomain;
if (pCodedValueDomain != null)
{
for (int k = 0; k <= pCodedValueDomain.CodeCount - 1; k++)
{
dicDomainValues = new Dictionary<string, string>();
string name = pCodedValueDomain.get_Value(k).ToString();
string value = pCodedValueDomain.get_Name(k).ToString();
dicDomainValues.Add("DisplayText", value);
dicDomainValues.Add("Value", name);
lstDics.Add(dicDomainValues);
}
}
}
}
else
{
opt.Result = "Field not found";
}
JsonObject result = new JsonObject();
result.AddString("Result", opt.Result);
result.AddObject("Options", lstDics);
return Encoding.UTF8.GetBytes(result.ToJson());
}