0
그래서, 나는 사용자가 다음과 같이 처음 25 개 레코드를 좋아하는 먹이를 검색하려고 :왜 동적 Json이 내 클래스 속성 값에 매핑되지 않습니까? 그리고 왜 Json이 무효가 되었습니까?
베이스GraphAPICall
다음 페이스 북에서 검색
Json
의 형식을
var access_token = HttpContext.Items["access_token"].ToString();
if (!string.IsNullOrEmpty(access_token))
{
var appsecret_proof = access_token.GenerateAppSecretProof();
var fb = new FacebookClient(access_token);
dynamic myFeed = await fb.GetTaskAsync(
("me/feed?fields=likes{{name,pic_large}}")
//GraphAPICall formats the json retrieved from facebook
.GraphAPICall(appsecret_proof));
string feed = myFeed;
var postList = new List<FBAnalyseViewModel>();
foreach (dynamic post in myFeed.data)
{
postList.Add(DynamicExtension.ToStatic<FBAnalyseViewModel>(post));
}
GraphAPI
위 얻을 아래로 여기 appsecret_proof
플러스 인수를 추가 :
//Iterate through the dynamic Object's list of properties, looking for match from the facebook mapping lookup
foreach (var entry in properties)
{
var MatchedResults = PropertyLookup.Where(x => x.facebookparent == entry.Key || x.facebookfield == entry.Key);
if (MatchedResults != null)
foreach (propertycontainer DestinationPropertyInfo in MatchedResults)
{
object mappedValue =null;
if (entry.Value.GetType().Name == "JsonObject")
{
//drill down on level to obtain a list of properties from the child set of properties
//of the dynamic Object
mappedValue = FindMatchingChildPropertiesRecursively(entry, DestinationPropertyInfo);
//child properity was not matched so apply the parent FacebookJson object as the entry value
if (mappedValue == null &&
DestinationPropertyInfo.facebookfield == entry.Key)
mappedValue = entry.Value;
}
else
{
if (String.IsNullOrEmpty(DestinationPropertyInfo.facebookparent) &&
DestinationPropertyInfo.facebookfield == entry.Key)
mappedValue = entry.Value;
}
//copy mapped value into destination class property
if (mappedValue != null)
if (DestinationPropertyInfo.facebookMappedProperty.PropertyType.Name == "DateTime")
{
DestinationPropertyInfo.facebookMappedProperty.SetValue(entity, System.DateTime.Parse(mappedValue.ToString()), null);
}
else
DestinationPropertyInfo.facebookMappedProperty.SetValue(entity, mappedValue, null);
}
}
return entity;
}
012 :
public static string GraphAPICall(this string baseGraphApiCall, params object[] args)
{
//returns a formatted Graph Api Call with a version prefix and appends a query string parameter containing the appsecret_proof value
if (!string.IsNullOrEmpty(baseGraphApiCall))
{
if (args != null &&
args.Count() > 0)
{
//Determine if we need to concatenate appsecret_proof query string parameter or inject it as a single query string paramter
string _graphApiCall = string.Empty;
if (baseGraphApiCall.Contains("?"))
_graphApiCall = string.Format(baseGraphApiCall + "&appsecret_proof={" + (args.Count() - 1) + "}", args);
else
_graphApiCall = string.Format(baseGraphApiCall + "?appsecret_proof={" + (args.Count() - 1) + "}", args);
//prefix with Graph API Version
return string.Format("v2.8/{0}", _graphApiCall);
}
else
throw new Exception("GraphAPICall requires at least one string parameter that contains the appsecret_proof value.");
}
else
return string.Empty;
}
나는 아래로 여기 내 속성 값에 대한 자동 매핑 기술을 사용
디버깅 모드에서 아래 그림과 같이 모델보기 속성에 null 값이 표시됩니다. 그리고
Json
은 facebook에 의해 반환되는 것은 유효하지 않습니다 json
을 serialize/deserialize. 해결 방법은 없습니까? 도와주세요.
편집 : 페이스 북 GrapAPICall
에서 검색된 Json
은 다음과 같습니다 :
{"data":[{"id":"1264038093655465_1274837905908817","likes":{"data":[{"name":"Sayed Zubair Hashimi","pic_large":"https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/14909900_10154513795037597_3241587822245799922_n.jpg?oh=54ead7e0ba74b45b632d96da1515ccf8&oe=591C4938","id":"10154729171332597"}
C#을 처음 사용하는 경우에는 약간 설명 할 수 있습니까? 어떻게 구현할 수 있습니까? –
리스트는 내가 볼 수있는 추가 브래킷을 제공하는 래퍼 역할을한다고 생각하십시오. – Netferret