103 Replies
this is a json format but i can't filter on it
u can deserialize it and then select it using linq
Newtonsoft.Json package
so something like that?
yes, but you need a class which will represent the data stored in the Json
yaeh so this?
yes exactly
ok thx i will try
then you can do
var ids = account.Select(x => x.Email).ToList();
and this will be a list of emails in this caseyou can also use system.text.json if you dont want any extra dependencies 🙂
ohh
But your string will not deserialize to the same type of object as presented on these screenshots
what do you mean?
Well, you have assigned list of users to the "data"
yes
do you need it?
no
do something like this instead
I mean the structure of you file
oh but the probem is
i can't do that away
do you store anything else than list of users in your json?
nope it are always the same values
but at the end of the file
i also ahve this
but i don't need meta
i only wnat my data
well I don't understand how you store this json
yeah its a twitter api pull
it is a list of my twitter followers
oh okay
so what i do is
can you show me whole structure of this Json?
like the whole json
on one screeshot
i mean the result
of this twitter api pull
yeah but look
i have a powerhshell script that does the work for me
and i run that script in my c# and get that information in a variable output
so do you want to see my powerhsell script or?
because i do a convertot)json
convertt-json
okay, so if you want to deserialize this json you need a structure that will cover the "data" and "meta" anyway
so it will be a class which will contain 2 props: List of Users which is data, and meta
this is how my powerhsell looks like
good
if you get the json as the result you need to deserialize it in order to do anything with it in c#
okey
uhh
it's very simple but you have to represent the json structure in c#
and then it will be easy
ok i will try thx
i dont know much about security but I would delete this screenshot if i was you
i removed my token
no problem
cool
but yeah i will remove it
the thing is you said i need to deserialize that object but is it an object?
It is a string for now. You have to represent it with a C# object just as it is here
i did it a little different
this is now my output
and i'm going to try to make three arrays
an array for id
name
and username
well that's not efficient way of doing it but do as you want
I would create a User class
and iterate through this output and covert it to
List<User>
is this more effient
without data and meta
yes
it's a json
so its easy now
now create a User class as I mentioned there
ow ok
thx btw
no problem
but the problem is when it print the type it still says System.strintg
string
and than i try this method
but it gives me this
this is my code in my main program btw
You must deserialize it to List<TwitterUser>
twitterfollowers is my json format
i do that right?
JsonConvert.DeserializeObject<List<TwitterUser>>(twitterFollowers)
thats my class
Yes
Check what i sent
var twitterUsers = JsonConvert.DeserializeObject<List<TwitterUser>>(twitterFollowers);
thats what i meant by u should learn the basics first....
List<TwitterUser>
and TwitterUser
are two completely different types, and thats why its complaining that u can not store on in anotheruse var when declaring a value
its much easier
but first understand types
yeah but you said
i need to use a class
yes class represents SINGLE twitter user
and your json contains MULTIPLE
so it needs to be an enumerable
so you can deserialize multiple users from a json
but now i can't say .id or .name
that's why it needs to be a List, Array, Enumerable etc.
yes you can
now you have list of them
so you have to specify which one of them you want the id of
u need to iterate over the elements of the list, each element is of type
TwitterAccount
and there u can access its propertiesif every Id then do this:
ow yeah i see
if you want the first one you can do
but remember that if this list is empty you will get an exception
so you better be using Linq
i thought that the whole process would be so much easier hahah
haha, no worries, it is easy but you need to understand how c# works
jep my c# skills are very bad
if you get used to it, such operation is a matter of minutes
you can always improve, dont worry
thx
youre welcome
oh yeah i see
so you mean soùmething like this
yeah yeah thx
Yes
now i made a twitter_id array
first a list
and than i convert that list to an array
I recommend using lists
because there are alot of benefits they say
but the problem is
later
what do you want to achieve?
i need to pass an int or string or array to contentful
wait a sec
this is my case
and i was thinking
if i can take twitter information
as a theme
that would be awesome
so first i need to deliver content to contentful
and that is my id name and username
i know nothing about this api unfortunately
no noprobel
no problem
but that is my goal
so yeah
You would have to describe what data you need in c# and I can help you with that
so it depends on what type of object contentful takes as an argument
That's what you should be looking at first
i also thought array
✅ This post has been marked as answered!