修改MS Graph响应以在现场显示 [英] Modifying MS Graph responses for display on site

查看:52
本文介绍了修改MS Graph响应以在现场显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个c#Web应用程序,该应用程序使用MS Graph连接到Azure AD B2C目录以显示用户数据.我正在寻找一种显示Graph Query返回的内容的最佳实践方法.我总是可以直接进行字符串格式化,但是我正在寻找更优化的方法.

I have a c# Web App that connects to Azure AD B2C directory with MS Graph to display user data. I'm looking for a best practice way to display the contents returned by Graph Query. I could always do straight forward string formatting, but I'm looking for something more optimal.

我使用

HttpResponseMessage httpmsg = await QueryGraphAsync("/users?$select=displayName");

,响应如下所示:

{"@ odata.context":" https://graph.microsoft.com/beta/$metadata#users(displayName)","value":[{"displayName":"xxx@xxx.xxx Xxx}]}

{"@odata.context":"https://graph.microsoft.com/beta/$metadata#users(displayName)","value":[{"displayName":"xxx@xxx.xxx Xxx"}]}

此时刻只有一名用户.我想要得到的是"xxx@xxx.xxx Xxx",而没有进行字符串修改,该字符串修改可以解决以下问题:找到displayName,跳过一些字符,直到找到引号为止.

There is just one user at this momment. What I'd like to get is "xxx@xxx.xxx Xxx" without playing around with string modification that would resolve around finding displayName, skipping a few chars and reading up untill it finds a quotation mark.

推荐答案

Microsoft Graph是一个REST API,它返回JSON.而不是进行字符串修改",您应该将响应视为JSON对象,可以轻松地将其转换为数组或字典.

The Microsoft Graph is a REST API which returns JSON. Rather than doing "string modification" you should treat the response as a JSON object, which can easily be converted into an array or dictionary.

var obj = JSON.parse('{"@odata.context":"https://graph.microsoft.com/beta/$metadata#users(displayName)","value":[{"displayName":"xxx@xxx.xxx Xxx"}]}')

var str = JSON.stringify(obj.value[0].displayName)

document.write(str)

这是对待来自Microsoft Graph的所有响应的方法.让我知道是否有帮助!

This is how you should treat all of the responses you get from the Microsoft Graph. Let me know if this helps!

这篇关于修改MS Graph响应以在现场显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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