I want to parse this JSON data but I have no idea how can I parse it.
{
"kind": "Testing",
"data": {
"modhash": "fffffghhhhhhbf0bb4601d6158db548b5296632215a0",
"dist": 75,
"children": [
{
"kind": "z4",
"data": {
"subreddit": "iOS",
"selftext": "I am iOS developer",
"author_fullname": "tyy_iif5q",
"saved": false,
"gilded": 0,
"clicked": false,
"title": "When is a good time to use docker?",
"subreddit_name_prefixed": "r/webdev",
"hidden": false,
"pwls": 6,
"downs": 0,
"hide_score": false,
"name": "t3_gwqan4",
"quarantine": false,
"link_flair_text_color": "dark",
"upvote_ratio": 0.96,
"subreddit_type": "public",
"ups": 277,
"total_awards_received": 0,
"is_original_content": false,
"is_reddit_media_domain": false,
"is_meta": false,
"can_mod_post": false,
"score": 277,
"author_premium": false,
"thumbnail": "self",
"edited": false,
"is_self": true,
"created": 1591333752,
"link_flair_type": "text",
"wls": 6,
"author_flair_type": "text",
"domain": "self.webdev",
"allow_live_comments": false,
"selftext_html": "<!-- SC_OFF --><div class=\"md\"><p>I just finished part 7 of the Full Stack Open course (<a href=\"https://www.fullstackopen.com/en\">www.fullstackopen.com/en</a>) and due to graphQL and typescript not being within the core content of the course, I thought I might try and learn docker. </p>\n\n<p>Turns out, trying to learn docker is just making me even more confused than when I didn't even know docker existed. </p>\n\n<p>​</p>\n\n<p>Could someone explain to me, when is a good time to use docker? How one would go about using docker, and when in someone's learning path would one ideally learn docker?</p>\n\n<p>​</p>\n\n<p>I am still learning react, databases, and overall front-end and back-end web development currently. The most I have done thus-far is hosting an app I made on heroku. I haven't setup a personal website, portfolio, or hosted an app on an independent website either.</p>\n</div><!-- SC_ON -->",
"archived": false,
"no_follow": false,
"is_crosspostable": true,
"pinned": false,
"over_18": false,
"media_only": false,
"can_gild": true,
"spoiler": false,
"locked": false,
"visited": false,
"subreddit_id": "t5_2qs0q",
"id": "gwqan4",
"is_robot_indexable": true,
"author": "Sensualities",
"num_comments": 127,
"send_replies": true,
"whitelist_status": "all_ads",
"contest_mode": false,
"author_patreon_flair": false,
"permalink": "/r/webdev/comments/gwqan4/when_is_a_good_time_to_use_docker/",
"parent_whitelist_status": "all_ads",
"stickied": false,
"url": "https://www.reddit.com/r/webdev/comments/gwqan4/when_is_a_good_time_to_use_docker/",
"subreddit_subscribers": 487697,
"created_utc": 1591304952,
"num_crossposts": 1,
"is_video": false
}
},
{
"kind": "t3",
"data": {
"subreddit": "iOS",
"selftext": "I am iOS developer",
"author_fullname": "tyy_iif5q",
"saved": false,
"gilded": 0,
"clicked": false,
"title": "When is a good time to use docker?",
"subreddit_name_prefixed": "r/webdev",
"hidden": false,
"pwls": 6,
"downs": 0,
"hide_score": false,
"name": "t3_gwqan4",
"quarantine": false,
"link_flair_text_color": "dark",
"upvote_ratio": 0.96,
"subreddit_type": "public",
"ups": 277,
"total_awards_received": 0,
"is_original_content": false,
"is_reddit_media_domain": false,
"is_meta": false,
"can_mod_post": false,
"score": 277,
"author_premium": false,
"thumbnail": "self",
"edited": false,
"is_self": true,
"created": 1591333752,
"link_flair_type": "text",
"wls": 6,
"author_flair_type": "text",
"domain": "self.webdev",
"allow_live_comments": false,
"selftext_html": "<!-- SC_OFF --><div class=\"md\"><p>I just finished part 7 of the Full Stack Open course (<a href=\"https://www.fullstackopen.com/en\">www.fullstackopen.com/en</a>) and due to graphQL and typescript not being within the core content of the course, I thought I might try and learn docker. </p>\n\n<p>Turns out, trying to learn docker is just making me even more confused than when I didn't even know docker existed. </p>\n\n<p>​</p>\n\n<p>Could someone explain to me, when is a good time to use docker? How one would go about using docker, and when in someone's learning path would one ideally learn docker?</p>\n\n<p>​</p>\n\n<p>I am still learning react, databases, and overall front-end and back-end web development currently. The most I have done thus-far is hosting an app I made on heroku. I haven't setup a personal website, portfolio, or hosted an app on an independent website either.</p>\n</div><!-- SC_ON -->",
"archived": false,
"no_follow": false,
"is_crosspostable": true,
"pinned": false,
"over_18": false,
"media_only": false,
"can_gild": true,
"spoiler": false,
"locked": false,
"visited": false,
"subreddit_id": "t5_2qs0q",
"id": "gwqan4",
"is_robot_indexable": true,
"author": "Sensualities",
"num_comments": 127,
"send_replies": true,
"whitelist_status": "all_ads",
"contest_mode": false,
"author_patreon_flair": false,
"permalink": "/r/webdev/comments/gwqan4/when_is_a_good_time_to_use_docker/",
"parent_whitelist_status": "all_ads",
"stickied": false,
"url": "https://www.reddit.com/r/webdev/comments/gwqan4/when_is_a_good_time_to_use_docker/",
"subreddit_subscribers": 487697,
"created_utc": 1591304952,
"num_crossposts": 1,
"is_video": false
}
}
],
"after": "ggggggg"
}
}
I want to parse this JSON data but I have no idea how can I parse it.I worked with simple json but I have no idea how can I parse nested json please help me. I want to parse this JSON data but I have no idea how can I parse it.I worked with simple json but I have no idea how can I parse nested json please help me.
Take a look at this library, it will help you ;)
https://pub.dev/packages/json_serializable
This lib will generate conversion code fromJson and toJson for each model annotated with #JsonSerializable
It take care of nested objects, type conversion and many other things ;)
Use this link to prepare model class of Json
https://javiercbk.github.io/json_to_dart/
HttpResponse response = callApi;
then after getting response just use json.decode;
then use fromjson Method of your Model generated through link and your whole json is parsed
Map userMap = jsonDecode(jsonString);
var user = User.fromJson(userMap);
User is Model created from site
At first you need a classes representing JSON with the method fromJson which parses JSON into your object.
Also you should use nested classes for nested JSON fields
Alternatively, you could generate necessary classes with this class generator
class JSONRepresentation {
final String kind;
final Data data;
JSONRepresentation({this.kind, this.data});
JSONRepresentation .fromJson(Map<String, dynamic> data)
: kind = data['kind'],
data = Data .fromJson(data['data']);
}
class Data {
final String modhash;
final int dist;
//final List<AnotherDataClass> children;
final String after;
Data({this.modhash, this.dist, this.after});
Data .fromJson(Map<String, dynamic> data)
: modhash = data['modhash'],
dist = data['dist'],
after = data['after'];
}
And then you can parse it using dart:convert and get data from objects representing JSON as below
import "dart:convert";
void main() {
var jsonData =
'{"kind": "Testing",
"data": {
"modhash": "fffffghhhhhhbf0bb4601d6158db548b5296632215a0",
"dist": 75,
//"children": [...],
"after": "ggggggg"}}';
var parsedJson = json.decode(jsonData);
var jsonRepresentationObject = JSONRepresentation.fromJson(parsedJson);
//Example of getting data from objects representing JSON
print("kind: "+ jsonRepresentationObject.kind +
"\nData modhash: " + jsonRepresentationObject.data.modhash);
}
You could test my example here - online dart compiler
I have installed a plugin to control my Samsung TV (https://github.com/xeenon/homebridge-samsung-tv) via my Homebridge server, however the developer did not provide a config-sample.json, hence why I am trying to make my own. I am entirely new to coding so please tell me what I am doing wrong.
This is the part of my config file for that accessory as of now (I will add the ip adress and mac adress later).
{
"bridge": {
"name": "Homebridge",
"username": "",
"port": 4318,
"pin": "031-45-154"
},
"accessories": [{
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_address": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1"
}]
}
When I am trying to start Homebridge I get the error
TypeError: Cannot read property 'forEach' of undefined
at new SamsungTvAccessory (usr/local/lib/node_modules/homebridge-samsung-tv-controller/index.js:76:10
If I however change the config file to
{
"bridge": {
"name": "Homebridge",
"username": "",
"port": 4318,
"pin": "031-45-154"
},
"accessories": [{
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_address": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1",
"enabledInputs": "true"
}]
}
where I added
"enabledInputs": "true"
i get the error
TypeError: config.enabledInputs.forEach is not a function
at new SamsungTvAccessory (usr/local/lib/node_modules/homebridge-samsung-tv-controller/index.js:76:10
I would really appreciate any help!
Did you try valid JSON ? Would tell you are missing brackets around, also from first lines of source it looks like. It should work like this
objectVar = {
"accessory": "samsungTv",
"name": "samsungTvAccessory",
"ip_adress": "",
"macAddress": "",
"polling": "true",
"pollingInterval": "1"
}
Or like this in case it you are using string somewhere: "{\"accessory\":\"samsungTv\",\"name\":\"samsungTvAccessory\",\"ip_adress\":\"\",\"macAddress\":\"\",\"polling\":\"true\",\"pollingInterval\":\"1\"}"
And then there are methods JSON.stringify(objectVar [, null, indent]) or JSON.parse(string) to convert to string or back. Stringify has also optional parameters - first is a replacer function and second indent if you want it people friendly formatted.
I want to specify a windows file path in my remote-ftp Atom configuration to reference my private key but I get some parsing issues. Here's my configuration:
{
"protocol": "sftp",
"host": "somehost.com",
"port": 22,
"user": "haha",
"pass": "testpass",
"promptForPass": false,
"remote": "/",
"local": "",
"agent": "",
"privatekey": "C:\Users\haha\Documents\Keys\test_private_key.ppk",
"passphrase": "",
"hosthash": "",
"ignorehost": true,
"connTimeout": 10000,
"keepalive": 10000,
"keyboardInteractive": false,
"keyboardInteractiveForPass": false,
"remoteCommand": "",
"remoteShell": "",
"watch": [],
"watchTimeout": 500
}
With the error:
Parse Error: "privatekey": "C:\Users\haha\Docum
So any idea how i escape Windows file paths for JSON parsing?
Your JSON is invalid, since backslashes need to be escaped per spec.
A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes
Hence, the value of privateKey should be "C:\\Users\\haha\\Documents\\Keys\\test_private_key.ppk".
If i export cookie from Chrome with "EditThisCookie" extension i see something like this:
{
"domain": ".youtube.com",
"expirationDate": 1599457462,
"hostOnly": false,
"httpOnly": false,
"name": "_ga",
"path": "/",
"sameSite": "no_restriction",
"secure": false,
"session": false,
"storeId": "0",
"value": "GA1.2.1666271553.1536385462",
"id": 1
}
and if i open Cookie databses (file Cookies in app folder) with DBExplorer, i see this:
expires_utc: 13243931062000000
How 13243931062000000 became 1599457462?
expires_utc is microseconds from 1601-01-01T00:00:00Z.
While expirationDate appears to be in Unix time, seconds from 1970-01-01T00:00:00Z.
You can find more information about expires_utc here.
I'm trying to migrate an old Plone 3.3 site that uses
FileSystemStorage using Mikko's Simple JSON export script.
Everything runs fine, except for the absence of a value on the image fields, which are returned as empty strings (''):
[
...
{
"allowDiscussion": false,
"contributors": [],
"creation_date": "2009-11-04T15:15:36-02:00",
"creators": [
"johndoe"
],
"description": "",
"effectiveDate": null,
"excludeFromNav": false,
"expirationDate": null,
"id": "banner_vertical.jpg",
"image": "",
"language": "",
"location": "",
"modification_date": "2009-11-04T15:15:37-02:00",
"portal_type": "Image",
"relatedItems": [],
"rights": "",
"subject": [],
"title": "Banner vertical",
"urlLegend": "http://"
},
...
]
Any hint?
(iw.fss version used is 2.8.0rc5).
FSS was not known or used by the site for which the script has been made.
You might want to retrofit convert() and other methods to support your use case.