为什么在将其解析为json之前必须使用tostring()字符串属性? [英] Why do I have to tostring() a string property before I can parse it to json?

查看:454
本文介绍了为什么在将其解析为json之前必须使用tostring()字符串属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

我遇到了一种奇怪的行为。我们在应用程序洞察自定义维度中记录JSON字符串,以便我们可以获得有关异常的结构化详细信当我们尝试查询动态数据时,我们会遇到这种我想要理解的奇怪行为。



在以下查询中,您可以看到我必须运行在我可以将它解析为字典之前,在字符串属性上使用tostring()。阅读预计要知道的属性名称。

I'm experiencing a weird behavior. We log JSON strings in application insights custom dimensions so we can have structured details about an exception. When we try to query that dynamic data, we have this strange behavior that I am trying to understand.

In the following query, you can see that I have to run tostring() on a string property before I can parse it to a dictionary. Read the projected property names to understand.

exceptions
| project
    thisWillReturnString = gettype(customDimensions.ExceptionDetail),
    thisWillReturnStringAgain = gettype(parse_json(customDimensions.ExceptionDetail)),
    thisWillReturnDictionary = gettype(parse_json(tostring(customDimensions.ExceptionDetail)))

有没有解释为什么我必须这样做,还是有更好的方法来实现将JSON字符串解析为字典?

Is there an explanation why I have to do this or is there a better to achieve parsing a JSON string to dictionary?

推荐答案

您好Pluc15,

Hi Pluc15,

根据以下示例,它确实显示它按您列出的每种格式返回相同的gettype。 

Based on the below sample, it does show that its returning the same gettype by each of the format you have listed. 

print customDimensionJsonString= dynamic({"name":"Alan", "age":21, "address":{"street":432,"postcode":"JLK32P"}})
| extend thiswillReturnString = gettype(customDimensionJsonString.name) 
| extend thiswillReturnStringAgain = gettype(parse_json(customDimensionJsonString.name)) 
| extend thiswillReturnStringOnly = gettype(parse_json(tostring(customDimensionJsonString.name) ) ) 

print customDimensionJsonString= dynamic({"name":"Alan", "age":21, "address":{"street":432,"postcode":"JLK32P"}})
| extend thiswillReturnlong = gettype(customDimensionJsonString.age) 
| extend thiswillReturnlongAgain = gettype(parse_json(customDimensionJsonString.age)) 
| extend thiswillReturnlongonly = gettype(parse_json(tostring(customDimensionJsonString.age) ) ) 




print customDimensionJsonString= dynamic({"name":"Alan", "age":21, "address":{"street":432,"postcode":"JLK32P"}})
| extend thiswillReturndictionary = gettype(customDimensionJsonString.address) 
| extend thiswillReturndictionaryAgain = gettype(parse_json(customDimensionJsonString.address)) 
| extend thiswillReturndictionaryonly = gettype(parse_json(tostring(customDimensionJsonString.address) ) ) 




如果你的customDimension与你看到的行为不一样,请你从数据集中分享一个例外示例。确保屏蔽了您可能拥有的任何敏感信息。 

If its not the same behavior you see with your customDimension, can you please share one sample of the exception from your dataset. Make sure you mask any of the sensitive information you might have. 

其他文档参考 -  

Additional documentation reference - 

ParseJson

dynamic

希望以上信息有所帮助,请回复任何疑问。

Hope the above information helps, please revert back for any queries.

 





这篇关于为什么在将其解析为json之前必须使用tostring()字符串属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆