Display Array Values?
-
Great plugin that does what I need, but I can’t figure out how to display the values of an array, such as the one below. Can you help?
"actions": [ { "date": "2009-02-25 00:00:00", "action": "Read first time. To print.", "type": [ "bill:introduced", "bill:reading:1" ], "actor": "lower (Desk)" }, { "date": "2009-02-26 00:00:00", "action": "From printer. May be heard in committee March 28.", "type": [ "other" ], "actor": "lower (Desk)" }, { "date": "2009-03-23 00:00:00", "action": "Referred to Com. on HEALTH.", "type": [ "committee:referred" ], "actor": "lower (Committee CX08)" }, ]
-
Thank you for your post. I’ll check this.
Ok, I can add this.
How would you mask the datafield?
Like {type:1} for the first field of the array?
Then {type:2}, {type:3} etc.?So the shortcut-code would be like this:
[jsoncontentimporter url=”http://….json” basenode=”actions”] {date}
{action}
{actor}
{type:1}
{type:2}
{type:3}
<hr>
[/jsoncontentimporter]Well (if you can’t tell 🙂 ) I’m a total novice. From a functional standpoint of how to craft a short code argument, that makes sense. The one issue/question I see is that, based on my research, it would need to somehow call each of the three objects in the array, so that it is displaying each of the records in the array separately. For example I have this code:
{ "object1": "data1", "another_object": "more data", "this_array_thing" : [ { "date": "2009-02-25 00:00:00", "action": "Read first time. To print."}, { "date": "2009-02-26 00:00:00", "action": "From printer. May be heard in committee March 28.", }, { "date": "2009-03-23 00:00:00", "action": "Referred to Com. on HEALTH." }, ]I would want the display to look like this:
Data1 – More data:
-2009-02-25 00:00:00, Read First Time, To Print
-2009-02-26 00:00:00, From Printer. May be Heard in Committee
-2009-03-23 00:00:00, Referred to Com on HEALTHEtc, with each record.
Would your suggestion accomplish that?
Hi,
install
https://downloads.wp.xz.cn/plugin/json-content-importer.1.0.3.zip andand:
1. http://reiseliste.de/extra/tmp/3.json
shortocde:
[jsoncontentimporter url=”http://www.reiseliste.de/extra/tmp/3.json” numberofdisplayeditems=”30″ basenode=””]
obj: {object1}, anobj: {another_object}{subloop-array:this_array_thing:5}dat:{date}, act: {action}
{/subloop-array}
[/jsoncontentimporter]2. http://reiseliste.de/extra/tmp/2.json
shortocde:
<table border=1>
[jsoncontentimporter url=”http://www.reiseliste.de/extra/tmp/2.json” numberofdisplayeditems=”2″ basenode=”actions”]
<tr><td>{date}</td><td>{action}</td><td>{actor}</td><td>
{subloop-array:type:5}{1:ifNotEmptyAddRight:aa
bb}{2:ifNotEmptyAddLeft:AA}{3:ifNotEmptyAddRight:BB}{/subloop-array}</td></tr>
[/jsoncontentimporter]
</table>Wow. Thanks for updating this to include this function. I can get the data to display when i use your example. However, when I try to display from a different data source, I can get objects to display fine but not the data within sub loop-array.
The entire code is below. And when I do this the “committee” and “Id” fields display fine. However, after that it displays the actual code i.e. “subloop-array:members:5}Â {name}
{/subloop-array}” in the page. So the result looks like this:Standing Committee on Jobs, Economic Development, and the Economy ;CAC000329
{subloop-array:members:5} {name}
{/subloop-array}What am I doing wrong?
[jsoncontentimporter url="http://openstates.org/api/v1//committees/CAC000329/?apikey=4680b1234b1b4c04a77cdff59c91cfe7"Â numberofdisplayeditems="30" basenode=""] {committee} ;{id} {subloop-array:members:5}Â {name} {/subloop-array} [/jsoncontentimporter]subloop and subloop-array do not work here.
but the solution is: use multiple [jsoncontentimporter]: each of it grabs and displays the part you need (with active caching the JSON-Url is fetched only once).E.g. for http://openstates.org/api/v1//committees/CAC000329/?apikey=4680b1234b1b4c04a77cdff59c91cfe7
[jsoncontentimporter url=”http://openstates.org/api/v1//committees/CAC000329/?apikey=4680b1234b1b4c04a77cdff59c91cfe7″%5D{committee}{chamber}{id}
[/jsoncontentimporter]
[jsoncontentimporter url=”http://openstates.org/api/v1//committees/CAC000329/?apikey=4680b1234b1b4c04a77cdff59c91cfe7″ basenode=”sources”]{url:ifNotEmptyAdd:}[/jsoncontentimporter]
<hr>
[jsoncontentimporter url=”http://openstates.org/api/v1//committees/CAC000329/?apikey=4680b1234b1b4c04a77cdff59c91cfe7″ basenode=”members”]
{name}: {leg_id}, {role}[/jsoncontentimporter]Excellent. That worked! Thank you.
you’re welcome.
please do me a favour and rate the plugin.
thank youHow can I access the elements in this sample:
…
“aspects”: [
{
“image”: {
“retina”: “http://myurl/wp-content/uploads/2014/11/SBK-08-Ansicht_001.jpg?820”,
“size_retina”: 290444,
“lastmodified”: 1416393176,
“id”: 820
},
“text”: “Vogelperspektive”
},
{
“image”: {
…I defined basenode=”aspects” and can access {text} – but how can I get “size_retina”?
{subloop:image:}
Size Retina: {size_retina}
Will not work (it’s no array)….Thanks a lot,
Detlef
Hi Detlef,
mail JSON as File or URL,please:
blog @ kux . deHi Detlef,
see
http://kux.de/extra/json/somejson/6.json
Up to this version the plugin expects an object after “aspects”, not an array encapsulated by “[]”.
In the next version the basenodeparameter will have an number as attribute, e.g. “aspects:0” means select first array-item.Bernhard
Will do. Also plan to make a donation to support further development. Keep it up.
Hi Bernhard,
using your JSON sample with:
[jsoncontentimporter url=”http://kux.de/extra/json/somejson/6.json” numberofdisplayeditems=”3″ basenode=”aspects”]
{text}
{subloop:image:}
Event: {retina}
{/subloop}
[/jsoncontentimporter]I got:
Vogelperspektive
Event: {retina}{text}
Event: {retina}and a lot of “Undefined variable: subloopNode in …/json-content-importer/class-json-parser.php on line 90”
Detlef
Hi Detlef,
thanks for sending me the JSON-Url via Mail. I’ll work on that.
Bernhard
Hi Detlef,
thanks for mailing. I’ll send you details via mail.
And: there is a new version 1.1.0:
https://downloads.wp.xz.cn/plugin/json-content-importer.1.1.0.zipBefore I release it as “stable” I would be happy with some user-tests.
New is the very much enhanced template-engine for supporting more JSON-structures.Best
Bernhard
The topic ‘Display Array Values?’ is closed to new replies.