本文整理汇总了C#中JsonObject.AddArray方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.AddArray方法的具体用法?C# JsonObject.AddArray怎么用?C# JsonObject.AddArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.AddArray方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIdsOfLayersThatHaveMetadata
/// <summary>
/// Returns a JSON serialized array listing all of the feature layers in the map service, converted to a byte array.
/// </summary>
/// <param name="boundVariables">Not used by this method, but required for method signature..</param>
/// <param name="outputFormat">The only supported format is "json".</param>
/// <param name="requestProperties">Not used by this method, but required for method signature.</param>
/// <param name="responseProperties">Not used by this method, but required for method signature</param>
/// <returns></returns>
private byte[] GetIdsOfLayersThatHaveMetadata(NameValueCollection boundVariables,
string outputFormat,
string requestProperties,
out string responseProperties)
{
responseProperties = null;
var idArray = GetIdsOfLayersThatHaveMetadata();
JsonObject output = new JsonObject();
output.AddArray("layerIds", idArray.Select(i => i as object).ToArray());
return Encoding.UTF8.GetBytes(output.ToJson());
}
示例2: LayersResHandler
private byte[] LayersResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
CustomLayerInfo[] layerInfos = GetLayerInfos();
JsonObject[] jos = new JsonObject[layerInfos.Length];
for (int i = 0; i < layerInfos.Length; i++)
jos[i] = layerInfos[i].ToJsonObject();
JsonObject result = new JsonObject();
result.AddArray("layersInfo", jos);
string json = result.ToJson();
return Encoding.UTF8.GetBytes(json);
}
示例3: GetRasterStatisticsOperHandler
/*
*该函数用来实现对影像服务中的影像进行统计,统计各波段值中的最大最小值
*
*
*/
private byte[] GetRasterStatisticsOperHandler(NameValueCollection boundVariables,
JsonObject operationInput,
string outputFormat,
string requestProperties,
out string responseProperties)
{
_logger.LogMessage(ServerLogger.msgType.infoDetailed, _soename + ".GetRasterStatistics", 8000, "request received");
if (!_supportRasterItemAccess)
throw new ArgumentException("The image service does not have a catalog and does not support this operation");
responseProperties = null;
long? objectID;
//case insensitive
bool found = operationInput.TryGetAsLong("objectID", out objectID);
if (!found || (objectID == null))
throw new ArgumentNullException("ObjectID");
IRasterCatalogItem rasterCatlogItem = null;
IRasterBandCollection rasterBandsCol = null;
IRasterStatistics statistics = null;
try
{
//获取栅格目录
rasterCatlogItem = _mosaicCatalog.GetFeature((int)objectID) as IRasterCatalogItem;
if (rasterCatlogItem == null)
{
_logger.LogMessage(ServerLogger.msgType.infoDetailed, _soename + ".GetRasterStatistics", 8000, "request finished with exception");
throw new ArgumentException("The input ObjectID does not exist");
}
}
catch
{
_logger.LogMessage(ServerLogger.msgType.infoDetailed, _soename + ".GetRasterStatistics", 8000, "request finished with exception");
throw new ArgumentException("The input ObjectID does not exist");
}
JsonObject result = new JsonObject();
try
{
rasterBandsCol = (IRasterBandCollection)rasterCatlogItem.RasterDataset;
List<object> maxvalues = new List<object>();
List<object> minvalues = new List<object>();
List<object> standarddeviationvalues = new List<object>();
List<object> meanvalues = new List<object>();
for (int i = 0; i < rasterBandsCol.Count; i++)
{
statistics = rasterBandsCol.Item(i).Statistics;
maxvalues.Add(statistics.Maximum);
minvalues.Add(statistics.Minimum);
standarddeviationvalues.Add(statistics.StandardDeviation);
meanvalues.Add(statistics.Mean);
Marshal.ReleaseComObject(statistics);
}
//结果序列号
result.AddArray("maxValues", maxvalues.ToArray());
result.AddArray("minValues", minvalues.ToArray());
result.AddArray("meanValues", meanvalues.ToArray());
result.AddArray("stdvValues", standarddeviationvalues.ToArray());
}
catch
{
_logger.LogMessage(ServerLogger.msgType.infoDetailed, "GetRasterStatistics", 8000, "request completed. statistics does not exist");
}
finally
{
if (rasterBandsCol != null)
Marshal.ReleaseComObject(rasterBandsCol);
if (rasterCatlogItem != null)
Marshal.ReleaseComObject(rasterCatlogItem);
}
_logger.LogMessage(ServerLogger.msgType.infoDetailed, _soename + ".GetRasterStatistics", 8000, "request completed successfully");
return Encoding.UTF8.GetBytes(result.ToJson());
}
示例4: RootResHandler
private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
IServerEnvironment3 senv = GetServerEnvironment() as IServerEnvironment3;
JsonObject result = new JsonObject();
JsonObject suinfoj = new JsonObject();
//get user info and serialize into JSON
IServerUserInfo suinfo = senv.UserInfo;
if (null != suinfo)
{
suinfoj.AddString("currentUser", suinfo.Name);
IEnumBSTR roles = suinfo.Roles;
List<string> rolelist = new List<string>();
if (null != roles)
{
string role = roles.Next();
while (!string.IsNullOrEmpty(role))
{
rolelist.Add(role);
role = roles.Next();
}
}
suinfoj.AddArray("roles", rolelist.ToArray());
result.AddJsonObject("serverUserInfo", suinfoj);
}
else
{
result.AddJsonObject("serverUserInfo", null);
}
return Encoding.UTF8.GetBytes(result.ToJson());
}
示例5: CustomLayer
//customLayers/{customLayersID}
//returns json with simplified layerinfo (name, id, extent)
private byte[] CustomLayer(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = "{\"Content-Type\" : \"application/json\"}";
if (null == boundVariables["customLayersID"] )
{
JsonObject obj = new JsonObject();
// put collection code here
CustomLayerInfo[] layerInfos = GetLayerInfos();
JsonObject[] jos = new JsonObject[layerInfos.Length];
for (int i = 0; i < layerInfos.Length; i++)
jos[i] = layerInfos[i].ToJsonObject();
obj.AddArray("customLayers", jos);
return Encoding.UTF8.GetBytes(obj.ToJson());
}
//layerID
int layerID = Convert.ToInt32(boundVariables["customLayersID"]);
//execute
CustomLayerInfo layerInfo = GetLayerInfo(layerID);
string json = layerInfo.ToJsonObject().ToJson();
return Encoding.UTF8.GetBytes(json);
}
示例6: GetSource
private byte[] GetSource(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null; //
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 + "'"; //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
int index = speciesFeatureClass.Fields.FindField("CITATION");
List<string> sources = new List<string>();
List<JsonObject> jsonObjects = new List<JsonObject>();
while ((feature = featureCursor.NextFeature()) != null) //iterate through the matching features
{
string source = feature.get_Value(index) as string;
if (InList(sources, source) == false)
{
JsonObject sourceJson = new JsonObject();
sourceJson.AddString("Source", source);
jsonObjects.Add(sourceJson);
sources.Add(source);
}
}
JsonObject result = new JsonObject(); //create the return json object
result.AddArray("sources", jsonObjects.ToArray());
return Encoding.UTF8.GetBytes(result.ToJson()); //return the json
}
示例7: QueryPoint
private byte[] QueryPoint(ESRI.ArcGIS.Geometry.IPoint location, double distance)
{
if (distance <= 0.0)
throw new ArgumentOutOfRangeException("distance");
// Buffer the point.
ITopologicalOperator topologicalOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator)location;
IGeometry queryGeometry = topologicalOperator.Buffer(distance);
// Query the feature class.
ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilter();
spatialFilter.Geometry = queryGeometry;
spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
spatialFilter.GeometryField = m_fcToQuery.ShapeFieldName;
IFeatureCursor resultsFeatureCursor = m_fcToQuery.Search(spatialFilter, true);
// Loop through the features, clip each geometry to the buffer
// and total areas by attribute value.
topologicalOperator = (ESRI.ArcGIS.Geometry.ITopologicalOperator)queryGeometry;
int classFieldIndex = m_fcToQuery.FindField(m_mapFieldToQuery);
// System.Collections.Specialized.ListDictionary summaryStatsDictionary = new System.Collections.Specialized.ListDictionary();
Dictionary<string, double> summaryStatsDictionary = new Dictionary<string, double>();
// Initialize a list to hold JSON geometries.
List<JsonObject> jsonGeometries = new List<JsonObject>();
IFeature resultsFeature = null;
while ((resultsFeature = resultsFeatureCursor.NextFeature()) != null)
{
// Clip the geometry.
IPolygon clippedResultsGeometry = (IPolygon)topologicalOperator.Intersect(resultsFeature.Shape,
ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension);
clippedResultsGeometry.Densify(0, 0); // Densify to maintain curved appearance when converted to JSON.
// Convert the geometry to JSON and add it to the list.
JsonObject jsonClippedResultsGeometry = Conversion.ToJsonObject(clippedResultsGeometry);
jsonGeometries.Add(jsonClippedResultsGeometry);
// Get statistics.
IArea area = (IArea)clippedResultsGeometry;
string resultsClass = resultsFeature.get_Value(classFieldIndex) as string;
// If the class is already in the dictionary, add the current feature's area to the existing entry.
if (summaryStatsDictionary.ContainsKey(resultsClass))
summaryStatsDictionary[resultsClass] = (double)summaryStatsDictionary[resultsClass] + area.Area;
else
summaryStatsDictionary[resultsClass] = area.Area;
}
// Use a helper method to get a JSON array of area records.
JsonObject[] areaResultJson = CreateJsonRecords(summaryStatsDictionary) as JsonObject[];
// Create a JSON object of the geometry results and the area records.
JsonObject resultJsonObject = new JsonObject();
resultJsonObject.AddArray("geometries", jsonGeometries.ToArray());
resultJsonObject.AddArray("records", areaResultJson);
// Get byte array of json and return results.
byte[] result = Encoding.UTF8.GetBytes(resultJsonObject.ToJson());
return result;
}
示例8: GetWISynonyms
private JsonObject GetWISynonyms(object[] records, Boolean? excludeWISiteCodes)
{
DataTable dt = new DataTable();
DataColumn syn = new DataColumn("syn", typeof(string));
dt.Columns.Add(syn);
DataRow row;
string code;
row = dt.NewRow();
foreach (JsonObject obj in records)
{
row = dt.NewRow();
obj.TryGetString("s", out code);//the synonym parameter is just named 's' in the json to keep it small
row["syn"] = code;
dt.Rows.Add(row);
}
string storedProcedureName = null;
if (excludeWISiteCodes == true)
{
storedProcedureName = "IWC_GetWISiteSynonymsExcludingWISiteCodes";
}
else
{
storedProcedureName = "IWC_GetWISiteSynonyms";
}
SqlCommand cmd = new SqlCommand(storedProcedureName, sqlConn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = cmd.Parameters.AddWithValue("@data", dt);
param.SqlDbType = SqlDbType.Structured;
SqlDataReader reader = cmd.ExecuteReader();
List<SiteSynonym> siteCodes = new List<SiteSynonym>();
SiteSynonym[] siteCodesArray = null;
if (reader.HasRows)
{
while (reader.Read())
{
SiteSynonym siteObj = new SiteSynonym();
siteObj.s = reader.GetString(0);
siteObj.c = reader.GetString(1);
siteCodes.Add(siteObj);
}
siteCodesArray = siteCodes.ToArray();
}
reader.Close();
JsonObject jsonObj = new JsonObject();
jsonObj.AddArray("siteCodes", siteCodesArray);
return jsonObj;
}
开发者ID:andrewcottam,项目名称:IWC-ArcGIS-ServerObjectExtensions,代码行数:47,代码来源:InternationalWaterbirdCensusExtensions.cs
示例9: backgroundWorker1_DoWork
//.........这里部分代码省略.........
foreach (JsonObject js_field in ls_fields_cache)
{
object value = fea_poi.get_Value(i);
string fieldtype;
js_field.TryGetString("type", out fieldtype);
string fieldname;
js_field.TryGetString("name", out fieldname);
#region
if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeString))
{
js_attributes.AddString(fieldname, value.ToString());
}
else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeOID))
{
js_attributes.AddLong(fieldname, long.Parse(value.ToString()));
}
else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeInteger))
{
if (value.ToString() == "")
{
value = 0;
}
js_attributes.AddLong(fieldname, long.Parse(value.ToString()));
}
else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeSmallInteger))
{
if (value.ToString() == "")
{
value = 0;
}
js_attributes.AddLong(fieldname, long.Parse(value.ToString()));
}
else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeDouble))
{
if (value.ToString() == "")
{
value = 0;
}
js_attributes.AddDouble(fieldname, double.Parse(value.ToString()));
}
else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeDate))
{
if (value.ToString() == "")
{
value = DateTime.MinValue;
}
js_attributes.AddDate(fieldname, DateTime.Parse(value.ToString()));
}
else if (fieldtype == Enum.GetName(typeof(esriFieldType), esriFieldType.esriFieldTypeSingle))
{
if (value.ToString() == "")
{
value = 0;
}
js_attributes.AddBoolean(fieldname, bool.Parse(value.ToString()));
}
#endregion
i++;
}
js_fea.AddJsonObject("attributes", js_attributes);
js_fea.AddJsonObject("geometry", Conversion.ToJsonObject(fea_poi.Shape));
}
else
{
IAnnotationFeature anno_fea = fea_poi as IAnnotationFeature;
ITextElement ele = anno_fea.Annotation as ITextElement;
//string text = ele.Text.Replace(System.Environment.NewLine, " ");
string text = ele.Text;
ITextSymbol sym = ele.Symbol;
IFontDisp font = sym.Font;
double symsize = sym.Size;
string fontname = font.Name;
decimal fontsize = font.Size;
string.Format(@"a"":""");
JsonObject js_symbol = new JsonObject(
string.Format(@"{{""type"" : ""esriTS"",""color"": [255,255,255],""haloSize"" : 0,""haloColor"" : [255,255,255,0],""verticalAlignment"" : ""bottom"",""horizontalAlignment"" : ""center"",""size"": {0},""angle"": 0,""xoffset"": 0,""yoffset"": 0,""font"" : {{""family"" : ""{2}"",""size"" : {3},""style"" : ""normal"",""weight"" : ""normal"",""decoration"" : ""none""}},""text"":""{1}""}}",symsize,text,fontname,fontsize));
js_fea.AddJsonObject("symbol", js_symbol);
IArea pshp = fea_poi.Shape as IArea;
js_fea.AddJsonObject("geometry", Conversion.ToJsonObject(pshp.Centroid));
}
ls_features.Add(js_fea);
fea_poi = cur_poi.NextFeature();
}
response.AddArray("features", ls_features.ToArray());
client.StringSet(ns+grid_id.ToString(), response.ToJson());
ReleaseCOMObject(cur_poi);
grid_id++;
progressBar1.BeginInvoke((Action)(() =>
{
progressBar1.Increment(1);
}));
}
}
MessageBox.Show("Build Cache Successfully!");
this.button1.BeginInvoke((Action)(()=>
{
ListCaches();
this.button1.Enabled = true;
}));
}
示例10: BuildMeta
/// <summary>
/// Build Meta Info
/// </summary>
private void BuildMeta()
{
IFeatureClass fc_poi = m_fcName.Open() as IFeatureClass;
IGeoDataset ds_poi = fc_poi as IGeoDataset;
int xmin = (int)Math.Floor(ds_poi.Extent.XMin);
int ymin = (int)Math.Floor(ds_poi.Extent.YMin);
int xmax = (int)Math.Ceiling(ds_poi.Extent.XMax);
int ymax = (int)Math.Ceiling(ds_poi.Extent.YMax);
int size = int.Parse(this.tbxSize.Text);
int step = (int)Math.Ceiling((xmax - xmin) * 1.0 / size);
string ns = "poi:" + this.tbxCacheName.Text + ":";
IDatabase client = m_redis.GetDatabase();
client.StringSet(ns + "size", size.ToString());
client.StringSet(ns + "xmin", xmin.ToString());
client.StringSet(ns + "ymin", ymin.ToString());
client.StringSet(ns + "xmax", xmax.ToString());
client.StringSet(ns + "ymax", ymax.ToString());
client.StringSet(ns + "step", step.ToString());
JsonObject response = new JsonObject();
List<JsonObject> ls_fields_cache = new List<JsonObject>();
for (int i = 0; i < fc_poi.Fields.FieldCount; i++)
{
IField field = fc_poi.Fields.get_Field(i);
JsonObject js_f = new JsonObject();
js_f.AddString("name", field.Name);
js_f.AddString("type", Enum.GetName(typeof(esriFieldType), field.Type));
js_f.AddString("alias", field.AliasName);
if (field.Type == esriFieldType.esriFieldTypeString)
{
js_f.AddString("length", field.Length.ToString());
}
else
{
js_f.AddString("length", "");
}
ls_fields_cache.Add(js_f);
}
response.AddArray("fields", ls_fields_cache.ToArray());
if (fc_poi.ShapeType == esriGeometryType.esriGeometryPoint)
{
response.AddString("geometryType", "esriGeometryPoint");
}
else if (fc_poi.ShapeType == esriGeometryType.esriGeometryPolyline)
{
response.AddString("geometryType", "esriGeometryPolyline");
}
else if (fc_poi.ShapeType == esriGeometryType.esriGeometryPolygon)
{
response.AddString("geometryType", "esriGeometryPolygon");
}
IGeoDataset gds_poi = fc_poi as IGeoDataset;
JsonObject js_sr = new JsonObject();
js_sr.AddLong("wkid", gds_poi.SpatialReference.FactoryCode);
response.AddJsonObject("spatialReference", js_sr);
client.StringSet(ns + "response", response.ToJson());
client.SetAdd("poi:caches", this.tbxCacheName.Text);
}
示例11: RootHandler
private byte[] RootHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
JsonObject result = new JsonObject();
result.AddArray("layers", m_layers.Values.Select(i => i.ToJsonObject()).ToArray<JsonObject>());
return Encoding.UTF8.GetBytes(result.ToJson());
}
示例12: ToJsonObject
public JsonObject ToJsonObject()
{
JsonObject result = new JsonObject();
if (DisplayFieldName != null) {
result.AddString("displayFieldName", DisplayFieldName);
}
if (Fields.Count > 0) {
JsonObject[] fields = new JsonObject[Fields.Count];
for (int i = 0; i < Fields.Count; i += 1) {
IField field = Fields[i];
JsonObject fjson = new JsonObject();
fjson.AddString("name", field.Name);
fjson.AddString("alias", field.AliasName);
fjson.AddString("type", FIELD_TYPE_NAMES[(int)field.Type]);
fjson.AddLong("length", field.Length);
fields[i] = fjson;
}
result.AddArray("fields", fields);
}
if (GeometryType != esriGeometryType.esriGeometryAny) {
result.AddString("geometryType", GEOMETRY_TYPE_NAMES[(int)GeometryType]);
}
if (Features.Count > 0) {
JsonObject[] features = new JsonObject[Features.Count];
for (int i = 0; i < Features.Count; i += 1) {
features[i] = Features[i].ToJsonObject();
}
result.AddArray("features", features);
}
return result;
}