本文整理汇总了C#中JSONObject.ParseString方法的典型用法代码示例。如果您正苦于以下问题:C# JSONObject.ParseString方法的具体用法?C# JSONObject.ParseString怎么用?C# JSONObject.ParseString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONObject
的用法示例。
在下文中一共展示了JSONObject.ParseString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnExportAsJSON_Click
private void btnExportAsJSON_Click(object sender, RoutedEventArgs e)
{
string dataframeName;
string outFile;
IMapLayerInfos pMLInfos = null;
IMapLayerInfo pMLI = null;
//checking the existence of the output folder
//DirectoryInfo outDirInfo = new DirectoryInfo(txtOutputFolder.Text);
string outDir = txtOutputFolder.Text + "\\" + System.IO.Path.GetFileNameWithoutExtension(txtMXD.Text);
if (Directory.Exists(outDir))
{
MessageBoxResult msgRes = System.Windows.MessageBox.Show(String.Format("Folder already exists \n{0}. \nDo you want to over write it?", outDir), "Output Folder", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (msgRes == MessageBoxResult.No)
{
System.Windows.MessageBox.Show("Operation is cancelled", "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
else
{
try
{
Directory.Delete(outDir, true);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(String.Format("Failed to delete the folder \n{0}\n\n{1}", outDir, ex.Message), "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
}
}
Directory.CreateDirectory(outDir);
prsProgress.IsIndeterminate = false;
prsProgress.Visibility = System.Windows.Visibility.Visible;
TreeViewItem pTVIDataframe = null;
for (int i = 0; i < m_pMapServer.MapCount; i++)
{
dataframeName = m_pMapServer.get_MapName(i);
if (dataframeName != m_pMapServer.DefaultMapName)
continue;
//ONLY for the default dataframe
pTVIDataframe = tvwLayers.Items[0] as TreeViewItem;
//getting REST resources including layer infos
string restOutputResource = Utils.GetLayersResource(m_pMapServer);
JSONObject jObject = new JSONObject();
jObject.ParseString(restOutputResource);
IJSONArray layers = null;
jObject.TryGetValueAsArray("layers", out layers);
pMLInfos = m_pMapServer.GetServerInfo(dataframeName).MapLayerInfos;
prsProgress.Maximum = pMLInfos.Count;
for (int j = 0; j < pMLInfos.Count; j++)
{
pMLI = pMLInfos.get_Element(j);
if (pMLI.IsFeatureLayer)
{
bool isSelected = false;
IsLayerSelectedForExport(pTVIDataframe, pMLI.ID, ref isSelected);
if (isSelected)
{
IJSONObject layer = (IJSONObject)layers.get_Value(j);
String renderer = Utils.GetRendererFromLayer(layer.ToJSONString(null));
outFile = string.Format(@"{0}\{1:000} {2}.json", outDir, pMLI.ID, Utils.ValidateFileName(pMLI.Name));
try
{
File.WriteAllText(outFile, renderer);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(String.Format("Failed to write content to the file\n{0}\n\n{1}", outFile, ex.Message), "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Error);
prsProgress.Visibility = System.Windows.Visibility.Hidden;
return;
}
}
}
prsProgress.Value += 1;
}
}
prsProgress.Visibility = System.Windows.Visibility.Hidden;
System.Windows.MessageBox.Show(String.Format("Conversion Completed\nOutput Path: {0}", outDir), "JSON Conversion", MessageBoxButton.OK, MessageBoxImage.Information);
}
示例2: GetRendererFromLayer
/// <summary>
/// Extracts renderer information from a layer resource
/// </summary>
/// <param name="layerResource">json representation of layer</param>
/// <returns></returns>
public static string GetRendererFromLayer(String layerResource)
{
String jsonRenderer = "";
IJSONObject jObject = new JSONObject();
jObject.ParseString(layerResource);
IJSONObject joDrawingInfo = new JSONObject();
jObject.TryGetValueAsObject("drawingInfo", out joDrawingInfo);
//if no drawingInfo found, say for group layers
if (joDrawingInfo == null)
return jsonRenderer;
jsonRenderer = joDrawingInfo.ToJSONString(null);
return jsonRenderer;
}