Facebook Graph API - JSON data - json

I am getting the following data in JSON format by the Facebook graph API. However it looks like it is in invalid JSON format. The JSON formatter says that the error is in line 1. What is this error ?
{
data = (
{
application = {
id = 2409997254;
name = Likes;
};
"created_time" = "2013-05-05T07:51:41+0000";
from = {
id = 100000347121257;
name = "Rishab Gulati";
};
id = "notif_746853089_182660043";
link = "http://www.facebook.com/photo.php?fbid=10151457234013090&set=a.427064503089.223857.746853089&type=1";
object = "<null>";
title = "Rishab Gulati, Deepika Gurnani and 2 other people like your photo.";
to = {
id = 746853089;
name = "Ashish Agarwal";
};
unread = 1;
"updated_time" = "2013-05-05T10:48:33+0000";
}
);
paging = {
next = "https://graph.facebook.com/746853089/notifications?format=json&access_token=**xxxxxxxxxx";
previous = "https://graph.facebook.com/746853089/notifications?format=json&access_token=**SNIP**&limit=5000&since=1367740301&__paging_token=notif_746853089_182660043&__previous=1";
};
summary = {
"unseen_count" = 1;
"updated_time" = "2013-05-05T10:48:33+0000";
};
}

This data is incorrect and isn't what Facebook supplies
{
"data": [
{
Where as your JSON above shows
{
data = (
{
There is a ( when there should be a {
Also consider not giving your access token out in public.

Related

SwiftUI - Extract specific key from JSON Reponse

I'm trying to extract a specific key from JSON. I am using the Stripe API in combination with Firebase Cloud functions.
I am printing the data using:
print(success!["charges"])
This is the output:
data = (
{
amount = 4500;
"amount_captured" = 4500;
captured = 1;
created = 1610732200;
currency = gbp;
description = "<null>";
dispute = "<null>";
disputed = 0;
"failure_code" = "<null>";
"failure_message" = "<null>";
"fraud_details" = {
};
id = "ch_1I9wE0GX6DUCOIM8aadiMKBU";
invoice = "<null>";
livemode = 0;
metadata = {
};
object = charge;
})
I can get the charges section of the response, but I need to access the id key within the data array. I just need the simple value, I don't need to save it, I just need to it to pass as a parameter.

How do I consume a JSon object that has no headers?

My C# MVC5 Razor page returns a Newtonsoft json link object to my controller (the "1" before \nEdit |" indicates that the checkbox is checked:
"{\"0\": [\"6146\",\"Kimball\",\"Jimmy\",\"General Funny Guy\",\"277\",\"Unite\",\"Jun 2019\",\"\",\"\",\"1\",\"\nEdit |\nDetails\n\n \n\"],\"1\": [\"6147\",\"Hawk\",\"Jack\",\"\",\"547\",\"Painters\",\"Jun 2019\",\"\",\"\",\"on\",\"\nEdit |\nDetails\n\n \n\"]}"
How do I parse this?
I am using a WebGrid to view and I want to allow the users to update only the lines they want (by checking the checkbox for that row), but it doesn't include an id for the 's in the dom. I figured out how to pull the values, but not the fieldname: "Last Name" , value: "Smith"... I only have the value and can't seem to parse it... one of my many failed attempts:
public ActoinResult AttMods(string gridData)
{
dynamic parsedArray = JsonConvert.DeserializeObject(gridData);
foreach (var item in parsedArray)
{
string[] itemvalue = item.Split(delimiterChars);
{
var id = itemvalue[0];
}
}
I finally sorted this one out..If there is a more dynamic answer, please share... I'll give it a few days before I accept my own (admittedly clugy) answer.
if(ModelState.IsValid)
{
try
{
Dictionary <string,string[]> log = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string[]>>(gridData);
foreach (KeyValuePair<string,string[]> keyValue in log)
{
if (keyValue.Value[9] == "1")//Update this row based on the checkbox being checked
{
var AttendeeID = keyValue.Value[0];
int intAttendeeID = 0;
if (int.TryParse(AttendeeID, out intAttendeeID))//Make sure the AttendeeID is valid
{
var LName = keyValue.Value[1];
var FName = keyValue.Value[2];
var Title = keyValue.Value[3];
var kOrgID = keyValue.Value[4];
var Org = keyValue.Value[5];
var City = keyValue.Value[7];
var State = keyValue.Value[8];
var LegalApproval = keyValue.Value[9];
tblAttendee att = db.tblAttendees.Find(Convert.ToInt32(AttendeeID));
att.FName = FName;
att.LName = LName;
att.Title = Title;
att.kOrgID = Convert.ToInt32(kOrgID);
att.Organization = Org;
att.City = City;
att.State = State;
att.LegalApprovedAtt = Convert.ToBoolean(LegalApproval);
}
}
}
db.SaveChanges();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
You can avoid assigning the var's and just populate the att object with the KeyValue.Value[n] value, but you get the idea.

Parse Bloomberg API response to JSON in python3

How can I convert the response message that returned from using bloomberg API in (python3 and flask) in to JSON
here is a response example:
ReferenceDataResponse = {
securityData[] = {
securityData = {
security = "FB EQUITY"
eidData[] = {
}
fieldExceptions[] = {
}
sequenceNumber = 0
fieldData = {
PX_LAST = 186.270000
VOLUME = 16746904.000000
}
}
securityData = {
security = "IBM EQUITY"
eidData[] = {
}
fieldExceptions[] = {
}
sequenceNumber = 1
fieldData = {
PX_LAST = 134.400000
VOLUME = 2551009.000000
}
}
}
}
dealing with it with the comming piece of code :
if str(msg.messageType()) == "ReferenceDataResponse":
securities = msg.getElement('securityData')
securities_count = securities.numValues()
for i in range(securities_count):
security = securities.getValueAsElement(i)
ticker = security.getElementAsString('security')
if (security.hasElement('fieldData')):
fields = security.getElement('fieldData')
fields_count = fields.numElements()
for j in range (fields_count):
security_dict = None
field = fields.getElement(j)
f_name = field.name()
f_value = field.getValueAsString()
security_dict = {"ticker":ticker ,"f_name":f_name , "f_value":f_value}
bloom_data.append(security_dict)
give me (Object of type Name is not JSON serializable)
now, I cant not access the name object to reach the name of the fields
any help will be very appreciated
After a lot of search I found this doc that is very helpful for as a schema for using the bloomberg api for dealing with the response ....
Here's the link ==> api schema
example for handeling respnse using python3:
bloom_data = []
if str(msg.messageType()) == "ReferenceDataResponse":
securities = msg.getElement('securityData')
securities_count = securities.numValues()
for i in range(securities_count):
security = securities.getValueAsElement(i)
ticker = security.getElementAsString('security')
if (security.hasElement('fieldData')):
fields = security.getElement('fieldData')
fields_count = fields.numElements()
for j in range (fields_count):
security_dict = None
field = fields.getElement(j)
f_name = field.name()
f_value = field.getValueAsString()
security_dict = {"ticker":ticker ,"f_name":str(f_name) , "f_value":f_value}
bloom_data.append(security_dict)

How to store JSON Dictionary response in NSMutableArray

This is my response ... My dictnary name is "msg"
{
Result = {
Data = {
engine = {
service = {
data = (
{
checked = 1;
field = 1;
name = Ettersyn;
},
{
checked = 1;
field = 1;
name = "Med Alpha VP";
},
{
checked = 0;
field = 0;
name = "Med B.IMP.";
}
);
"engine_service_id" = 1;
"engine_service_name" = "4 Cyl";
};
type = {
"engine_id" = 1;
"engine_name" = Benzin;
};
};
tact = {
service = {
data = (
{
checked = 0;
field = 1;
name = "Little ettersyn";
},
{
checked = 0;
field = 1;
name = "Short ettersyn";
}
);
"tact_service_id" = 2;
"tact_service_name" = "21-50 hk";
};
type = {
"tact_id" = 1;
"tact_name" = "2 Takt";
};
};
};
status = success;
};
}
I try to to store the data like this
var arrayMain : NSMutableArray = msg.valueForKey("Result")?.valueForKey("Data") as NSMutableArray
My problem is i got "EXC_BAD_ACCESS" error While running ... Am also check allocation of array ... I try to store it in NSMutableDictionary its work perfectly ... How can i store this response in NSMutableArray ?
If you look carefully at the response data structure you'll see the problem.
This first operation: msg.valueForKey("Result") would return an dictionary with two key/values; a "Data" dictionary, and "Status" string.
Your second operation .valueForKey("Data") would return a dictionary with two key/values; an "Engine and "Tact" dictionary.
Because it's a dictionary, you can create a dictionary from it, which is what you said worked, or you're going to have to rethink how you want to store if if indeed you want it in an array, but you can't create an array directly from a dictionary - they are different data structures.
You cannot assign Dictionary object to Array, that's why it is giving the error.
But you can store that dictionary to array as:
var arrayMain : NSMutableArray = NSMutableArray()
arrayMain.addObject(msg.valueForKey("Result")?.valueForKey("Data"))

How to fix the lambda expression delegate error?

I am using this method to get data
private void getNews(int cat_id, int page)
{
this.progress.Visibility = Visibility.Visible;
var m = new SharpGIS.GZipWebClient();
Microsoft.Phone.Reactive.Observable.FromEvent<DownloadStringCompletedEventArgs>(m, "DownloadStringCompleted").Subscribe(l =>
{
try
{
//List<NewsKeys> deserialized = JsonConvert.DeserializeObject<List<NewsKeys>>(r.EventArgs.Result);
ObservableCollection<NewsKeys> deserialized = JsonConvert.DeserializeObject<List<NewsKeys>>(l.EventArgs.Result);
foreach (NewsKeys item in deserialized)
{
items.Add(new NewsKeys { nId = item.nId, title = item.title, shortDesc = item.shortDesc, fullDesc = item.fullDesc, tags = item.tags, smallPic = item.smallPic, bigPic = item.bigPic, video = item.video, audio = item.audio, youtube = item.youtube, doc = item.doc, date_create = item.date_create, date_modify = item.date_modify, date_publish = item.date_publish, catId = item.catId, viewOrder = item.viewOrder, viewCount = item.viewCount, viewStatus = item.viewStatus, viewHome = item.viewHome, uId = item.uId, uFname = item.uFname });
}
}
catch (Exception)
{
MessageBox.Show("Sorry, Some unexpected error.");
}
});
m.DownloadStringAsync(new Uri(Resource.NEWS_API+cat_id+"&page="+page));
}
The error i get is
Error 1 Cannot convert lambda expression to type 'System.IObserver>' because it is not a delegate type C:\Users\Adodis\Documents\Visual Studio 2010\Projects\TV\NewsListPage.xaml.cs 51 133
I have tried all the fixes but unable to fix this problem. Am using the same block in different method in a different class it is working fine but, this method in this class killing me. Please help me if you have idea on this.
Thanks in advance.
Try this (I've separated the Select and Subscribe operations):
var m = new SharpGIS.GZipWebClient();
Observable.FromEvent<DownloadStringCompletedEventArgs>(m, "DownloadStringCompleted")
.Select(l => l.EventArgs.Result)
.Subscribe(res =>
{
try
{
var deserialized = JsonConvert.DeserializeObject<List<NewsKeys>>(res);
foreach (NewsKeys item in deserialized)
{
items.Add(
new NewsKeys
{
nId = item.nId,
title = item.title,
shortDesc = item.shortDesc,
fullDesc = item.fullDesc,
tags = item.tags,
smallPic = item.smallPic,
bigPic = item.bigPic,
video = item.video,
audio = item.audio,
youtube = item.youtube,
doc = item.doc,
date_create = item.date_create,
date_modify = item.date_modify,
date_publish = item.date_publish,
catId = item.catId,
viewOrder = item.viewOrder,
viewCount = item.viewCount,
viewStatus = item.viewStatus,
viewHome = item.viewHome,
uId = item.uId,
uFname = item.uFname
});
}
}
catch (Exception)
{
MessageBox.Show("Sorry, Some unexpected error.");
}
});
m.DownloadStringAsync(new Uri("Resource.NEWS_API" + cat_id + "&page=" + page));