How to get an image url in this json file in flutter - json

in this json file I want to get original_ur but when i cant get it , can some one help me how to get it please
{
"orders": {
"order_items":[
{
"product_min":{
"colors":[
{
"media":[
{
"original_url": b
"https://royalpetiq.com/royalpet2/public//storage/10628/msg5212971698-890.jpg",
}
]
}
]
}
}
]
}
}

go on quicktype id site and create model from this json after just creat object of that claass and parse this json response and after that you can get valu like
x.orders.order_items[0].product_min.colors[0].media[0].original_url

here is your json path
x.orders.order_items[0].product_min.colors[0].media[0].original_url

try {
var json = """{
"orders": {
"order_items":[
{
"product_min":{
"colors":[
{
"media":[
{
"original_url": "https://royalpetiq.com/royalpet2/public//storage/10628/msg5212971698-890.jpg"
}
]
}
]
}
}
]
}
}""";
var data = jsonDecode(json);
var url = data["orders"]["order_items"][0]["product_min"]["colors"][0]
["media"][0]["original_url"];
print("Url: $url");
} catch (e) {
print(e);
}
I think your json should be like that.
Here the url has a b at the beginning and a comma after the url which is not the correct syntax for json

Related

Newtonsoft.json SelectToken Replace differs from SelectTokens Replace in foreach with a NullReferenceException

Hope anybody could guide me here. I spend some hours on it and can't understand what's going on.
Mission: Replace a json element by a jsonpath search tag. (sort of $ref feature)
In my code example below i want to replace the value of DataReaderUser by a value found by the json path search $.UsersAndGroups.Users[?(#.Name == 'OMDASAccountUser')].Username . In this case it should result in the value "contoso\SVCSCOM-DO-OMDAS"
The code below works as expected.. the issue is below this code ..
https://dotnetfiddle.net/gEjggK
using System;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
string json = #"{
""SQLServer"": {
""SQLReportingServices"": {
""AccountSettings"": {
""DataReaderUser"": {""$JsonPath"": ""$.UsersAndGroups.Users[?(#.Name == 'OMDASAccountUser')].Username""},
}
}
},
""UsersAndGroups"": {
""Users"": [
{
""Name"": ""OMActionAccountUser"",
""Username"": ""contoso\\SVCSCOM-DO-OMDAS"",
},
{
""Name"": ""OMDASAccountUser"",
""Username"": ""contoso\\SVCSCOM-DO-OMDAS"",
}
]
}
}";
JObject jo = JObject.Parse(json);
var JsonPath = jo.SelectToken("..$JsonPath");
JsonPath.Parent.Parent.Replace(jo.SelectToken(JsonPath.ToString()));
Console.WriteLine(jo.ToString());
}
}
The output will be :
{
"SQLServer": {
"SQLReportingServices": {
"AccountSettings": {
"DataReaderUser": "contoso\\SVCSCOM-DO-OMDAS"
}
}
},
"UsersAndGroups": {
"Users": [
{
"Name": "OMActionAccountUser",
"Username": "contoso\\SVCSCOM-DO-OMDAS"
},
{
"Name": "OMDASAccountUser",
"Username": "contoso\\SVCSCOM-DO-OMDAS"
}
]
}
}
Now the issue:
I want to do the same for all possible jsonpaths refers. So i use the SelectTokens and an foreach . But it looks like the behavior is different , the parents are null.
https://dotnetfiddle.net/lZW3XP
using System;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
string json = #"{
""SQLServer"": {
""SQLReportingServices"": {
""AccountSettings"": {
""DataReaderUser"": {""$JsonPath"": ""$.UsersAndGroups.Users[?(#.Name == 'OMDASAccountUser')].Username""},
}
}
},
""UsersAndGroups"": {
""Users"": [
{
""Name"": ""OMActionAccountUser"",
""Username"": ""contoso\\SVCSCOM-DO-OMDAS"",
},
{
""Name"": ""OMDASAccountUser"",
""Username"": ""contoso\\SVCSCOM-DO-OMDAS"",
}
]
}
}";
JObject jo = JObject.Parse(json);
var JsonPaths = jo.SelectTokens("..$JsonPath");
foreach (var JsonPath in JsonPaths )
{
JsonPath.Parent.Parent.Replace(jo.SelectToken(JsonPath.ToString()));
}
Console.WriteLine(jo.ToString());
}
}
And the output:
Run-time exception (line 34): Object reference not set to an instance of an object.
Stack Trace:
[System.NullReferenceException: Object reference not set to an instance of an object.]
at Newtonsoft.Json.Linq.JsonPath.PathFilter.GetNextScanValue(JToken originalParent, JToken container, JToken value)
at Newtonsoft.Json.Linq.JsonPath.ScanFilter.<ExecuteFilter>d__4.MoveNext()
at Program.Main() :line 34
would be great to get some directions since i am spinning my head here.
michel
SelectTokens uses lazy evaluation and if you modify the token while enumerating all matches it can break in unexpected ways. A simple fix is to add ToArray() to force eager evaluation:
var JsonPaths = jo.SelectTokens("..$JsonPath").ToArray();

How To Get Childs From Json Response Firebase

current_date = date.today()
result = firebase.get('/InstaFollow',None)
data = json.dumps(result,indent=2)
print(data)
Python
{
"User2Follow": {
"16_04_2020": {
"20:20:51": {
"Delightedtiktoks": "\"55822\""
},
"20:21:04": {
"Delightedtiktoks": "\"55822\""
},
"20:38:45": {
"Delightedtiktoks": "\"Testuser101\""
}
}
}
}
Hey Guys Im Making A Project With Python,And Im Stuck.
Im Using A realtime database from firerbase,this is my response(Json)
Im Trying To Get A List With The Dates "16_04_2020"(This JSON File only has 1 date,but there will be more )
Anyone Know How I Can Get A List With All Dates?
So if would run my script my output should be : "16_04_2020"
Try this.
import json
myjson = '''
{
"User2Follow": {
"16_04_2020": {
"20:20:51": {
"Delightedtiktoks": "55822"
},
"20:21:04": {
"Delightedtiktoks": "55822"
},
"20:38:45": {
"Delightedtiktoks": "Testuser101"
}
}
}
}'''
object = json.loads(myjson)
dates = [date for date in object['User2Follow']]
print(dates)
Output:
['16_04_2020']

I want to parse json, but it does not

I want to get tmX, tmY from this json, but I can not get it.
How can I get a value?
I do not think there's anything more to write ...
{
"list":[
{
"_returnType":"json",
"map":"",
"numOfRows":"10",
"pageNo":"1",
"tmX":"196543.111337",
"tmY":"173653.845412"
}
],
"totalCount":1
}
QString tmX, tmY;
if (jsonObj.contains("list")) {
QJsonObject listObj = jsonObj["list"].toObject();
if (listObj.contains("tmX"))
tmX = listObj["tmX"].toString();
if (listObj.contains("tmY"))
tmY = listObj["tmY"].toString();
}

Get value of variable from json using jsonslurper

I have the following JSON code:
{
"TIMESTAMP":"2017-05-26-20.22.40.016000",
"dateTime":"2017-05-26H-20.22.4",
"AMUCCY1":"ADP",
"rates":[
{
"AMUCCY2":"AED",
"AMURAT":"1.000000000",
"AMUNXRT":0
},
{
"AMUCCY2":"AFA",
"AMURAT":"1.000000000",
"AMUNXRT":0
},
{
"AMUCCY2":"ALL",
"AMURAT":"1.000000000",
"AMUNXRT":0
},
{
"AMUCCY2":"AMD",
"AMURAT":"1.000000000",
"AMUNXRT":0
}
]
}
Is there quick way in groovy where I could loop through each of the 'rates' and get the value of, let's say 'AMUCCY2' ?
I tried doing this code:
jsonObj.rates.each {
def toCurrencyMap = jsonObj.rates.AMUCCY2
LOG.info "${toCurrencyMap}"
}
but the toCurrencyMap returns an array of all four values of this field. I only want to get each value; not all.
Any suggestions is appreciated.
You can try this:
jsonObj.rates.each {
println it.AMUCCY2
}
If you want list / array:
def result = jsonObj.rates.collect { it.AMUCCY2 }
println result

Groovy to create JSON

Here's an SQL query I had to execute in Groovy:
def resultset_bio = sql.rows("SELECT author, isbn FROM Book WHERE genre = 'biography'")
I'm trying to convert this data into JSON. For that, I am using this code:
def json = new groovy.json.JsonBuilder()
json {
Biographies(resultset_bio.collect{[id: it]})
}
println json.toPrettyString()
}
The JSON output I expect should be like this:
{
"Biographies":
{
"SSS": ["XXX",456988]
}
}
But instead, I'm getting this:
{
"Biographies": [
{
"id": {
"author": "XXX",
"isbn": 456988,
}
}
]
}
How should I change my code? Please help.
Now id is passed as a static key.
Try:
json {
Biographies(resultset_bio.collect{[(it.id): it]})
}
You do not have the book title in your select so you can't make a mapping of title to book info.
In order to get the list layout of each row (which is a map) grouped by author:
def authorBios = resultset_bio.groupBy { it.author }
def biographies = authorBios.collectEntries { author, row ->
[author, row*.values()]
}
json {
Biographies(biographies)
}