Why I get the following error at offset 6 with the following code. It makes an HTTP Request, gets a Json back, should go through the Json and create the object IMDBInfo. The json is valid, obviously processing, and the data class is as easy as it could be..., but I don't get the point of the error:
Error:
Exception in thread "main" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 6: Expected beginning of the string, but got {
JSON input: {"d":[{"i":{"height":741,"imageUrl":.....
at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24)
...
Code:
class StreamingAvailability() {
var IMDBName : String = ""
fun findOriginalTitle(title: String) = runBlocking {
val client = HttpClient(Apache) {
install(JsonFeature) {
serializer = KotlinxSerializer(kotlinx.serialization.json.Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
coerceInputValues = true
allowStructuredMapKeys = true
})
}
}
val result : IMDBInfo = client.get {
url {
protocol = URLProtocol.HTTPS
encodedPath = "auto-complete"
host = "imdb8.p.rapidapi.com"
}
parameter("q", title)
headers {
append(HttpHeaders.Accept, "application/json")
append(HttpHeaders.ContentType, ContentType.Application.Json)
append(HttpHeaders.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36")
append(HttpHeaders.Authorization, API_KEY)
append("X-Rapidapi-Key", API_KEY)
append("X-Rapidapi-Host", "imdb8.p.rapidapi.com")
}
}
println(result.d)
}
}
Data Classes:
import kotlinx.serialization.Serializable
#Serializable data class D(
val l: String
)
#Serializable data class IMDBInfo(
val d: List<D>,
)
JSON which is valid and processed in the response:
{
"d": [{
"i": {
"height": 800,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMTMzNDkzMTcyOV5BMl5BanBnXkFtZTcwNDIzMjM2MQ##._V1_.jpg",
"width": 550
},
"id": "tt1080016",
"l": "Ice Age: Dawn of the Dinosaurs",
"q": "feature",
"rank": 7936,
"s": "Ray Romano, John Leguizamo",
"v": [{
"i": {
"height": 360,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMTMyODMyMDY3MF5BMl5BanBnXkFtZTcwMTg2MTM0Mg##._V1_.jpg",
"width": 480
},
"id": "vi3380019993",
"l": "Ice Age: Dawn of the Dinosaurs -- Trailer #2",
"s": "2:30"
}, {
"i": {
"height": 360,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMjFkMjY3NzYtNTkzOS00ZWM4LThhN2MtZTk0MTczMGRjZmNiXkEyXkFqcGdeQXVyNzU1NzE3NTg#._V1_.jpg",
"width": 480
},
"id": "vi64291353",
"l": "Ice Age: Dawn of the Dinosaurs",
"s": "0:59"
}, {
"i": {
"height": 360,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMTg1NTgwNzg5M15BMl5BanBnXkFtZTgwOTc4NzkxMzE#._V1_.jpg",
"width": 480
},
"id": "vi2023162649",
"l": "Ice Age: Dawn of the Dinosaurs -- Trailer #1",
"s": "2:34"
}],
"vt": 5,
"y": 2009
}, {
"i": {
"height": 500,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMjE1NTEwMTEwOF5BMl5BanBnXkFtZTcwMDA2MDQyOQ##._V1_.jpg",
"width": 357
},
"id": "tt1907779",
"l": "The Dinosaur Project",
"q": "feature",
"rank": 39963,
"s": "Richard Dillane, Peter Brooke",
"v": [{
"i": {
"height": 480,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMTg3ODAxMTg4OF5BMl5BanBnXkFtZTcwNTg0OTI4OA##._V1_.jpg",
"width": 640
},
"id": "vi3951666969",
"l": "The Dinosaur Project Trailer",
"s": "2:11"
}],
"vt": 1,
"y": 2012
}, {
"i": {
"height": 789,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMTk0MTI1NTI1MF5BMl5BanBnXkFtZTcwMDg2Mzc4OQ##._V1_.jpg",
"width": 603
},
"id": "tt2303110",
"l": "Rise of the Dinosaurs",
"q": "feature",
"rank": 46988,
"s": "Gary Stretch, Corin Nemec",
"y": 2013
}, {
"i": {
"height": 1285,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMWI4ZjZmYTktOWIxNS00MmMyLTk5YzctNGQ4ZDg3MmIxYmZkXkEyXkFqcGdeQXVyODg1Njg2Njc#._V1_.jpg",
"width": 900
},
"id": "tt7818384",
"l": "Dino the Dinosaur",
"q": "TV series",
"rank": 65868,
"s": "June Yoon",
"y": 2016,
"yr": "2016-2019"
}, {
"i": {
"height": 475,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMTU2NDkyODcxM15BMl5BanBnXkFtZTcwNTA0MzQyMQ##._V1_.jpg",
"width": 301
},
"id": "tt0136639",
"l": "Extreme Dinosaurs",
"q": "TV series",
"rank": 83132,
"s": "Scott McNeil, Cusse Mankuma",
"y": 1997,
"yr": "1997-1997"
}, {
"i": {
"height": 475,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMTIzODM4NTYyMV5BMl5BanBnXkFtZTcwODYzMzAzMQ##._V1_.jpg",
"width": 253
},
"id": "tt0103400",
"l": "The Dinosaurs!",
"q": "TV series",
"rank": 189562,
"s": "Barbara Feldon, Robert Bakker",
"y": 1992,
"yr": "1992-"
}, {
"i": {
"height": 2048,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BNGFlNDczMjMtNmQ1OS00MTJjLTk4NDQtNWU2OGY4Y2M2NDdlXkEyXkFqcGdeQXVyNjE4OTE4OTc#._V1_.jpg",
"width": 1418
},
"id": "tt14162824",
"l": "The Dinosaur",
"q": "feature",
"rank": 211135,
"s": "Veikko Aaltonen, Rauni Mollberg",
"y": 2021
}, {
"i": {
"height": 720,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BYjQ3MTU3ZjgtNDA5Zi00N2EwLWExNjctZWJhMzFlMGVjOGJjXkEyXkFqcGdeQXVyNTg0NTkzNTk#._V1_.jpg",
"width": 1280
},
"id": "tt6877360",
"l": "The Day the Dinosaurs Died",
"q": "TV movie",
"rank": 212976,
"s": "Alice Roberts, Ben Garrod",
"y": 2017
}],
"q": "diedinos",
"v": 1
}
Just rename the class D to something that has more than 1 symbol. I've created an issue for this really weird behavior.
Related
Trying to make our dashboard as code while using CloudFormation. Getting an error while validating template with the embedded JSON String inside the YML File. It is having problems with the "SEARCH('{AWS/EC2,InstanceId) fields saying those are invalid strings. I have ran it through a JSON Linter and works fine. I have also deployed the CloudWatch Dashboard console just fine with the JSON.
Question:
Is there anyway to just wrap this section as a string for CloudFormation in the YML file so it doesn't get tripped up on the JSON string contents?
Example:
DetailedDashboard:
Type: "AWS::CloudWatch::Dashboard"
Properties:
DashboardName: "DetailedDashboard"
DashboardBody: !Sub
...,
{
"type": "metric",
"x": 6,
"y": 18,
"width": 6,
"height": 6,
"properties": {
"metrics": [
[ { "expression": "SEARCH('{AWS/EC2,InstanceId} NetworkIn', 'Average', 300)", "id": "network_in", "period": 300, "region": "us-east-1", "label": "net_in" } ],
[ { "expression": "SEARCH('{AWS/EC2,InstanceId} NetworkOut', 'Average', 300)", "id": "network_out", "period": 300, "region": "us-east-1", "label": "net_out" } ]
],
"view": "timeSeries",
"stacked": false,
"region": "us-east-1",
"title": "Network in/out by Host",
"stat": "Average",
"period": 300,
"yAxis": {
"left": {
"label": "bytes"
}
}
}
},
DetailedDashboard:
Type: 'AWS::CloudWatch::Dashboard'
Properties:
DashboardName: 'DetailedDashboard'
DashboardBody: !Sub |
{
"type": "metric",
"x": 6,
"y": 18,
"width": 6,
"height": 6,
"properties": {
"metrics": [
[ { "expression": "SEARCH('{AWS/EC2,InstanceId} NetworkIn', 'Average', 300)", "id": "network_in", "period": 300, "region": "us-east-1", "label": "net_in" } ],
[ { "expression": "SEARCH('{AWS/EC2,InstanceId} NetworkOut', 'Average', 300)", "id": "network_out", "period": 300, "region": "us-east-1", "label": "net_out" } ]
],
"view": "timeSeries",
"stacked": false,
"region": "us-east-1",
"title": "Network in/out by Host",
"stat": "Average",
"period": 300,
"yAxis": {
"left": {
"label": "bytes"
}
}
}
},
I want to use this JSON file for pandas, but this JSON file has some problem.
I got an error from the time I downloaded it, but I couldn't find the answer.
{
"content": "http://com.dataturks.a96-i23.open.s3.amazonaws.com/2c9fafb064277d86016431e33e4e003d/8186c3d1-e9d4-4550-8ec1-a062a7628787___0-26.jpg.jpeg",
"annotation": [{
"label": ["Face"],
"notes": "",
"points": [{
"x": 0.08615384615384615,
"y": 0.3063063063063063
}, {
"x": 0.1723076923076923,
"y": 0.45345345345345345
}],
"imageWidth": 650,
"imageHeight": 333
}, {
"label": ["Face"],
"notes": "",
"points": [{
"x": 0.583076923076923,
"y": 0.2912912912912913
}, {
"x": 0.6584615384615384,
"y": 0.46846846846846846
}],
"imageWidth": 650,
"imageHeight": 333
}],
"extras": null
} {
"content": "http://com.dataturks.a96-i23.open.s3.amazonaws.com/2c9fafb064277d86016431e33e4e003d/d1c32c8e-8050-482d-a6c8-b101ccba5b65___0de0ee708a4a47039e441d488615ebb7.png",
"annotation": [{
"label": ["Face"],
"notes": "",
"points": [{
"x": 0.7053087757313109,
"y": 0.23260437375745527
}, {
"x": 0.7692307692307693,
"y": 0.36182902584493043
}],
"imageWidth": 1280,
"imageHeight": 697
}],
"extras": null
}
It shows this message.
Error: Parse error on line 29:
..., "extras": null} { "content": "http:
---------------------^
Expecting 'EOF', '}', ',', ']', got '{'
How can I solve this problem?
Try this: it should work!
There's a problem with the way you started your JSON file
Use a square bracket to start and end with a square bracket [ ]
[
{
"content": "http://com.dataturks.a96-i23.open.s3.amazonaws.com/2c9fafb064277d86016431e33e4e003d/8186c3d1-e9d4-4550-8ec1-a062a7628787___0-26.jpg.jpeg",
"annotation": [{
"label": ["Face"],
"notes": "",
"points": [{
"x": 0.08615384615384615,
"y": 0.3063063063063063
}, {
"x": 0.1723076923076923,
"y": 0.45345345345345345
}],
"imageWidth": 650,
"imageHeight": 333
}, {
"label": ["Face"],
"notes": "",
"points": [{
"x": 0.583076923076923,
"y": 0.2912912912912913
}, {
"x": 0.6584615384615384,
"y": 0.46846846846846846
}],
"imageWidth": 650,
"imageHeight": 333
}],
"extras": null
} {
"content": "http://com.dataturks.a96-i23.open.s3.amazonaws.com/2c9fafb064277d86016431e33e4e003d/d1c32c8e-8050-482d-a6c8-b101ccba5b65___0de0ee708a4a47039e441d488615ebb7.png",
"annotation": [{
"label": ["Face"],
"notes": "",
"points": [{
"x": 0.7053087757313109,
"y": 0.23260437375745527
}, {
"x": 0.7692307692307693,
"y": 0.36182902584493043
}],
"imageWidth": 1280,
"imageHeight": 697
}],
"extras": null
}
]
Your JSON structure is wrong. Probably you want get array inside :
[
{
"content": "http://com.dataturks.a96-i23.open.s3.amazonaws.com/2c9fafb064277d86016431e33e4e003d/8186c3d1-e9d4-4550-8ec1-a062a7628787___0-26.jpg.jpeg",
"annotation": [
{
"label": [
"Face"
],
"notes": "",
"points": [
{
"x": 0.08615384615384615,
"y": 0.3063063063063063
},
{
"x": 0.1723076923076923,
"y": 0.45345345345345345
}
],
"imageWidth": 650,
"imageHeight": 333
},
{
"label": [
"Face"
],
"notes": "",
"points": [
{
"x": 0.583076923076923,
"y": 0.2912912912912913
},
{
"x": 0.6584615384615384,
"y": 0.46846846846846846
}
],
"imageWidth": 650,
"imageHeight": 333
}
],
"extras": null
},
{
"content": "http://com.dataturks.a96-i23.open.s3.amazonaws.com/2c9fafb064277d86016431e33e4e003d/d1c32c8e-8050-482d-a6c8-b101ccba5b65___0de0ee708a4a47039e441d488615ebb7.png",
"annotation": [
{
"label": [
"Face"
],
"notes": "",
"points": [
{
"x": 0.7053087757313109,
"y": 0.23260437375745527
},
{
"x": 0.7692307692307693,
"y": 0.36182902584493043
}
],
"imageWidth": 1280,
"imageHeight": 697
}
],
"extras": null
}
]
I am trying to get a nested value from a json content I get from an API Rest (Swagger). I want to access to the first "url" value:
val getFeedVersionURL = url("https://api.transitfeeds.com/v1/getFeedVersions?").GET <<? List(
"key" -> someKey,
"feed" -> "consorcio-regional-de-transportes-de-madrid/743",
"page" -> "1",
"limit" -> "10000",
"err" -> "1 (default)",
"warn" ->"1 (default)")
val response : Future[String] = Http.configure(_ setFollowRedirects true)(getFeedVersionURL OK as.String)
val src: String = getFeedVersionURL.toString()
response onComplete {
case Success(content) => {
println("Successful response" + content)
//Parse the content
val jsonObject = Json.parse(content)
//Get url value
val fileDownloadURL = (jsonObject \ "results" \ "versions" \ "url").as[String]
//Save the file
new URL(fileDownloadURL) #> new File("C:/Users//Desktop//file.zip") !!
}
case Failure(t) => {
println("An error has occured: " + t.getMessage)
}
}
This is the json I receive:
{
"status": "OK",
"ts": 1513600944,
"results": {
"total": 4,
"limit": 100,
"page": 1,
"numPages": 1,
"versions": [
{
"id": "consorcio-regional-de-transportes-de-madrid/743/20171127",
"f": {
"id": "consorcio-regional-de-transportes-de-madrid/743",
"ty": "gtfs",
"t": "Metro Ligero de Madrid GTFS",
"l": {
"id": 167,
"pid": 166,
"t": "Madrid, Spain",
"n": "Madrid",
"lat": 40.416775,
"lng": -3.70379
},
"u": {
"i": "http://crtm.maps.arcgis.com/home/item.html?id=aaed26cc0ff64b0c947ac0bc3e033196"
}
},
"ts": 1511848526,
"size": 403388,
"url": "https://transitfeeds.com/p/consorcio-regional-de-transportes-de-madrid/743/20171127/download",
"d": {
"s": "20170106",
"f": "20180629"
},
"err": [],
"warn": []
},
{
"id": "consorcio-regional-de-transportes-de-madrid/743/20170927",
"f": {
"id": "consorcio-regional-de-transportes-de-madrid/743",
"ty": "gtfs",
"t": "Metro Ligero de Madrid GTFS",
"l": {
"id": 167,
"pid": 166,
"t": "Madrid, Spain",
"n": "Madrid",
"lat": 40.416775,
"lng": -3.70379
},
"u": {
"i": "http://crtm.maps.arcgis.com/home/item.html?id=aaed26cc0ff64b0c947ac0bc3e033196"
}
},
"ts": 1506554131,
"size": 403052,
"url": "https://transitfeeds.com/p/consorcio-regional-de-transportes-de-madrid/743/20170927/download",
"d": {
"s": "20170106",
"f": "20180925"
},
"err": [],
"warn": []
},
{
"id": "consorcio-regional-de-transportes-de-madrid/743/20170526",
"f": {
"id": "consorcio-regional-de-transportes-de-madrid/743",
"ty": "gtfs",
"t": "Metro Ligero de Madrid GTFS",
"l": {
"id": 167,
"pid": 166,
"t": "Madrid, Spain",
"n": "Madrid",
"lat": 40.416775,
"lng": -3.70379
},
"u": {
"i": "http://crtm.maps.arcgis.com/home/item.html?id=aaed26cc0ff64b0c947ac0bc3e033196"
}
},
"ts": 1495816290,
"size": 408985,
"url": "https://transitfeeds.com/p/consorcio-regional-de-transportes-de-madrid/743/20170526/download",
"d": {
"s": "20170106",
"f": "20180526"
},
"err": [],
"warn": []
},
{
"id": "consorcio-regional-de-transportes-de-madrid/743/20161012",
"f": {
"id": "consorcio-regional-de-transportes-de-madrid/743",
"ty": "gtfs",
"t": "Metro Ligero de Madrid GTFS",
"l": {
"id": 167,
"pid": 166,
"t": "Madrid, Spain",
"n": "Madrid",
"lat": 40.416775,
"lng": -3.70379
},
"u": {
"i": "http://crtm.maps.arcgis.com/home/item.html?id=aaed26cc0ff64b0c947ac0bc3e033196"
}
},
"ts": 1476308287,
"size": 420670,
"url": "https://transitfeeds.com/p/consorcio-regional-de-transportes-de-madrid/743/20161012/download",
"d": {
"s": "20160101",
"f": "20170621"
},
"err": [],
"warn": []
}
]
}
}
The problem is I receive this error:
play.api.libs.json.JsResultException: JsResultException(errors:List((,List(ValidationError(error.expected.jsstring,WrappedArray())))))
Any ideas?
cchantep in the comment is correct. You'll need to pull out the versions key and deal with it appropriately. Here's some Very rough code that does what you want:
import play.api.libs.json._
val jsonObject = Json.parse(s) // s is that string you gave in your q
val fileDownloadURL: String = (jsonObject \ "results" \ "versions") match {
case JsDefined(JsArray(versions)) => versions.headOption match {
case Some(jsValue) => (jsValue \ "url").as[String]
case _ => "NOPE hope you got some logic here"
}
case nope => throw new IllegalArgumentException("handle this better than this!")
}
And I get:
res0: String = https://transitfeeds.com/p/consorcio-regional-de-transportes-de-madrid/743/20171127/download
Note that I did this using play 2.4 in my console, and for 2.3 and other versions there may be differences. If you provide the version of play you're using I can probably give you some more rough ideas about how to accomplish what you're up to.
Note that the above with the matching is one way, another way would be to use as a bunch
val thisToo = (jsonObject \ "results" \ "versions").as[JsArray].value.headOption.map(first => (first \ "url").as[String]).getOrElse(throw new IllegalArgumentException("handle this better than this!"))
I have the following json file I am importing into my component:
import { beer, wine, spririts, alcopop } from '../../config/calculator.json';
How can I use the json in my render?
Depending upon what was chosen I would like to use the data for each element, if user clicks beer, then show data for beer. For example, how would I loop through 'sizes' in 'beer'? This is my code so far:
{[drinkType].sizes.map((option, i) =>
<div value={option.id} key={i}>
{option}
</div>
)}
I would like to display the size name, pint, bottle, can etc
I get the error: Cannot read property 'map' of undefined
//calculator.json
{
"beer": {
"name": "Beer or cider",
"sizes": {
"568": {
"name": "Pint",
"size": 0.568,
"id": "pint",
"max": 10,
"icon": "beer_pint"
},
"440": {
"name": "Can",
"size": 0.44,
"id": "can",
"max": 10,
"icon": "beer_can"
},
"330": {
"name": "Bottle",
"size": "0.33",
"id": "bottle",
"max": "10",
"icon": "beer_bottle_330"
},
"275": {
"name": "Small bottle",
"size": 0.275,
"id": "smallBottle",
"max": 10,
"icon": "beer_bottle_275"
}
},
"strength": [4, 4.5, 5, 6, 7, 8, 9]
},
"wine": {
"name": "Wine or champagne",
"sizes": {
"125": {
"name": "Small glass",
"size": 0.125,
"id": "small",
"max": 10,
"icon": "wine_small_glass"
},
"175": {
"name": "Standard glass",
"size": 0.175,
"id": "std",
"max": 10,
"icon": "wine_standard_glass"
},
"250": {
"name": "Large glass",
"size": 0.25,
"id": "large",
"max": 10,
"icon": "wine_large_glass"
},
"1000": {
"name": "Bottle",
"size": 1,
"id": "bottle",
"max": 10,
"icon": "wine_bottle"
}
},
"strength": [9, 10, 10.5, 11, 11.5, 12, 13, 14, 15, 16, 17]
},
"spirits": {
"name": "Spirits or shots",
"sizes": {
"25": {
"name": "Single",
"size": 0.025,
"id": "single",
"max": 10,
"icon": "spirit_single"
},
"35": {
"name": "Large single",
"size": 0.035,
"id": "lgSingle",
"max": 10,
"icon": "spirit_large_single"
},
"50": {
"name": "Double",
"size": 0.05,
"id": "double",
"max": 10,
"icon": "spirit_double"
},
"70": {
"name": "Large double",
"size": 0.07,
"id": "lgDouble",
"max": 10,
"icon": "spirit_large_double"
},
"700": {
"name": "Bottle",
"size": 0.7,
"id": "bottle700",
"max": 3,
"icon": "spirit_bottles"
},
"1000": {
"name": "Bottle",
"size": 1,
"id": "bottle",
"max": 3,
"icon": "spirit_bottles"
}
},
"strength": [37, 40]
},
"alcopop": {
"name": "Alcopop",
"sizes": {
"275": {
"name": "Small bottle",
"size": 0.275,
"id": "small",
"max": 10,
"icon": "alcopops_small_bottle"
},
"330": {
"name": "Standard bottle",
"size": 0.33,
"id": "std",
"max": 10,
"icon": "alcopops_standard_bottle"
},
"750": {
"name": "Large bottle",
"size": 0.75,
"id": "large",
"max": 10,
"icon": "alcopops_large_bottle"
}
},
"strength": [5, 5.5]
}
}
.map does not work on objects like that,
map() is only for Arrays
Instead you can store the keys in array and use them, like,
import jsonData from '../../config/calculator';
...
//in constructor or any function
let sizes;
sizes={};
for(let i of Object.keys(jsonData)){
if(!sizes[i][0])sizes[i] = [];
for(let j of Object.keys(i.sizes)){
sizes[i].push(jsonData[i].sizes[j])
}
}
this.setState({
sizesArray:sizes
})
Now you can use this.state.sizesArray.map to iterate over sizes, like,
{this.state.sizes[drinkType].map((option, i) =>
<div value={option.id} key={i}>
{option}
</div>
)}
First, import your json inside the component:
import jsonData from '../../config/calculator'; //specify the appropriate location of the json file
Then you can access the "data" in your component in various ways. One way could be:
constructor() {
this.state = {
data: []
}
}
componentDidMount(){
this.setState({data: jsonData});
}
And accordingly, you can use this data(this.state.data).
I am trying to hide a layer in KineticJS that is built from a JSON string. The layer won't hide, however. If I try to hide a shape having an ID in the JSON, it does work. Not sure if I have incorrectly created my layer ID in the JSON, or if KineticJS has issues with layer showing/hiding. There is no console error. The layer just won't hide. KineticJS is version v5.1.1. Help?
Here's the relevant JSON....
{
"attrs": {
"width": 524,
"height": 500
},
"className": "Stage",
"children": [
{
"attrs": {},
"className": "Layer",
"id": "layer1",
"children": [
{
"attrs": {
"draggable": true
},
"className": "Group",
"children": [
{
"attrs": {
"id": "firstShape",
"x": 25,
"y": 25,
"radius": 190,
"fill": "green"
},
"className": "Circle"
},
{
"attrs": {
"width": "auto",
"height": "auto",
"x": 64,
"y": 120,
"text": "Some label",
"fontSize": 10,
"fontFamily": "Arial",
"fill": "white"
},
"className": "Text"
}
]
}
]
}
]
}
Here's the event handler which does the layer hide... I find that this is getting called correctly, and the layer just isn't hiding.
scope.$on('hideLayer', function(){
scope.kineticStageObj.get('#layer1').hide();
scope.kineticStageObj.draw();
});
Looks like your json is wrong. id of layer should be inside attrs object.
"attrs": {
"id: : "layer1"
},
Try this:
{
"attrs": {
"width": 524,
"height": 500
},
"className": "Stage",
"children": [
{
"attrs": {
"id": "layer1"
},
"className": "Layer",
"children": [
{
"attrs": {
"draggable": true
},
"className": "Group",
"children": [
{
"attrs": {
"id": "firstShape",
"x": 25,
"y": 25,
"radius": 190,
"fill": "green"
},
"className": "Circle"
},
{
"attrs": {
"width": "auto",
"height": "auto",
"x": 64,
"y": 120,
"text": "Some label",
"fontSize": 10,
"fontFamily": "Arial",
"fill": "white"
},
"className": "Text"
}
]
}
]
}
]
}