• Почему код не работает?

    @nickname_null Автор вопроса
    Сергей Соколов, спасибо, заменил var на const и всё работает
  • Почему код не работает?

    @nickname_null Автор вопроса
    а если у меня
    var task=$this.attr('href'); //task='t13'
    var id=$this.parent().attr('id'); //id='1 Часть'

    то
    json[id][task][0]
    не работает
  • Перебор json'а на php?

    @nickname_null Автор вопроса
    Дмитрий Дерепко, он вывел:
    <div class="spoiler">
    		<div class="spoiler-head">1 Часть</div>
    		<a href="t13">13</a><br><a href="t14">14</a><br><a href="t16">16</a><br><a href="t16">16</a><br><a href="t19–20">19–20</a><br><a href="t21–22">21–22</a><br><a href="t21–22">21–22</a><br><a href="t28">28</a><br><a href="t28">28</a><br><a href="t37–38">37–38</a><br><a href="t37–38">37–38</a><br><a href="t37–38">37–38</a><br><a href="t39–40">39–40</a><br><a href="t39–40">39–40</a><br><a href="t39–40">39–40</a><br><a href="t46">46</a><br><a href="t46">46</a><br><a href="t49–50">49–50</a><br><a href="t57">57</a><br><a href="t57">57</a><br><a href="t57">57</a><br><a href="t62">62</a><br><a href="t62">62</a><br><a href="t66">66</a><br><a href="t69">69</a><br><a href="t71">71</a><br><a href="t71">71</a><br><a href="t71">71</a><br><a href="t71">71</a><br><a href="t72">72</a><br><a href="t72">72</a><br><a href="t72">72</a><br><a href="t82">82</a><br><a href="t87">87</a><br><a href="t87">87</a><br><a href="t99">99</a><br><a href="t99">99</a><br><a href="t99">99</a><br><a href="t100">100</a><br><a href="t107">107</a><br><a href="t107">107</a><br><a href="t109">109</a><br><a href="t121">121</a><br><a href="t121">121</a><br><a href="t121">121</a><br><a href="t123–124">123–124</a><br><a href="t123–124">123–124</a><br><a href="t123–124">123–124</a><br><a href="t123–124">123–124</a><br><a href="t127–128">127–128</a><br><a href="t127–128">127–128</a><br><a href="t135">135</a><br><a href="t135">135</a><br><a href="t135">135</a><br><a href="t140–141">140–141</a><br><a href="t140–141">140–141</a><br><a href="t148–149">148–149</a><br><a href="t148–149">148–149</a><br><a href="t158">158</a><br><a href="t158">158</a><br><a href="t166–167">166–167</a><br><a href="t166–167">166–167</a><br><a href="t172">172</a><br><a href="t173">173</a><br><a href="t173">173</a><br><a href="t173">173</a><br><a href="t182–183">182–183</a><br><a href="t189">189</a><br><a href="t196–197">196–197</a><br><a href="t196–197">196–197</a><br><a href="t201">201</a><br><a href="t201">201</a><br><a href="t202–203">202–203</a><br><a href="t202–203">202–203</a><br><a href="t202–203">202–203</a><br><a href="t213">213</a><br><a href="t213">213</a><br><a href="t213">213</a><br><a href="t213">213</a><br><a href="t213">213</a><br><a href="t213">213</a><br><a href="t240–241">240–241</a><br><a href="t240–241">240–241</a><br><a href="t257">257</a><br><a href="t257">257</a><br><a href="t268">268</a><br><a href="t268">268</a><br><a href="t272">272</a><br><a href="t273">273</a><br><a href="t273">273</a><br><a href="t284–285">284–285</a><br><a href="t284–285">284–285</a><br><a href="t284–285">284–285</a><br>		<div class="spoiler-body extc">
    		</div>
    	</div>
    	<div class="spoiler">
    		<div class="spoiler-head">2 Часть</div>
    		<a href="t5">5</a><br><a href="t6–7">6–7</a><br><a href="t8">8</a><br><a href="t9">9</a><br><a href="t10–11">10–11</a><br><a href="t12">12</a><br><a href="t14">14</a><br><a href="t16–17">16–17</a><br><a href="t19">19</a><br><a href="t19">19</a><br><a href="t27">27</a><br><a href="t27">27</a><br><a href="t41">41</a><br><a href="t41">41</a><br><a href="t53">53</a><br><a href="t53">53</a><br><a href="t65">65</a><br><a href="t66">66</a><br><a href="t66">66</a><br><a href="t66">66</a><br><a href="t66">66</a><br><a href="t70">70</a><br><a href="t73–74">73–74</a><br><a href="t73–74">73–74</a><br><a href="t73–74">73–74</a><br><a href="t85">85</a><br><a href="t86">86</a><br><a href="t86">86</a><br><a href="t88">88</a><br><a href="t90">90</a><br><a href="t95">95</a><br><a href="t96">96</a><br><a href="t97">97</a><br><a href="t99–100">99–100</a><br><a href="t99–100">99–100</a><br><a href="t102">102</a><br><a href="t103">103</a><br><a href="t103">103</a><br><a href="t119">119</a><br><a href="t119">119</a><br><a href="t125–126">125–126</a><br><a href="t125–126">125–126</a><br><a href="t125–126">125–126</a><br><a href="t125–126">125–126</a><br><a href="t129–130">129–130</a><br><a href="t135">135</a><br><a href="t141">141</a><br><a href="t143">143</a><br><a href="t149">149</a><br><a href="t149">149</a><br><a href="t152">152</a><br><a href="t152">152</a><br><a href="t153">153</a><br><a href="t154–155">154–155</a><br><a href="t156">156</a><br><a href="t156">156</a><br><a href="t158">158</a><br><a href="t158">158</a><br><a href="t159–160">159–160</a><br><a href="t159–160">159–160</a><br><a href="t161">161</a><br><a href="t164">164</a><br><a href="t180–181">180–181</a><br><a href="t180–181">180–181</a><br><a href="t180–181">180–181</a><br><a href="t180–181">180–181</a><br><a href="t180–181">180–181</a><br><a href="t185">185</a><br><a href="t186–187">186–187</a><br><a href="t188–189">188–189</a><br><a href="t190">190</a><br><a href="t192">192</a><br><a href="t193–194">193–194</a><br><a href="t193–194">193–194</a><br><a href="t196">196</a><br><a href="t199">199</a><br><a href="t199">199</a><br><a href="t200–201">200–201</a><br><a href="t200–201">200–201</a><br><a href="t200–201">200–201</a><br><a href="t200–201">200–201</a><br>		<div class="spoiler-body extc">
    		</div>
    	</div>
  • Перебор json'а на php?

    @nickname_null Автор вопроса
    Дмитрий Дерепко,
    поменял
    $obj = json_decode($json, true);
    на
    $obj = json_decode($json);
    и всё заработало
  • Перебор json'а на php?

    @nickname_null Автор вопроса
    Дмитрий Дерепко,
    получился такой код:
    <?php
    $s = '{"part1": {"t13": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8ceb0f8.jpg"], "t14": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cec0b4.jpg"], "t16": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cee086.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cee4c9.jpg"], "t19\u201320": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf079c.jpg"], "t21\u201322": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf2ae5.jpg", "https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8cf2fa0.jpg"]}, "part2": {"t5": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d20a76.jpg"], "t6\u20137": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d219bc.jpg"], "t8": ["https://gdz-ru.com/attachments/images/tasks/000/109/238/0002/5c373b8d25274.jpg"]}}';
    $obj = json_decode($s, true);
    foreach ($obj as $key => $part) { ?>
    	<div class="spoiler">
    		<div class="spoiler-head"><?php echo $key?> Часть</div>
    		<?php 
    		foreach($obj->$key as $k => $a) {
    			if ($k[0] !== 't') continue;
    			foreach($a as $l) {	
    				$res = '<a href="' . $k . '">' . str_replace('t','',$k) . '</a>';
    				echo $res;
    				echo '<br>';
    			}
    		}?>
    		<div class="spoiler-body extc">
    		</div>
    	</div>
    <?php }

    но выдаёт ошибку:
    Notice: Trying to get property 'part1' of non-object in D:\Program Files\xampp\htdocs\test.php on line 8
    
    Warning: Invalid argument supplied for foreach() in D:\Program Files\xampp\htdocs\test.php on line 8
    part2 Часть
    Notice: Trying to get property 'part2' of non-object in D:\Program Files\xampp\htdocs\test.php on line 8
    
    Warning: Invalid argument supplied for foreach() in D:\Program Files\xampp\htdocs\test.php on line 8
  • Перебор json'а на php?

    @nickname_null Автор вопроса
    мне нужно, чтобы спойлер появился 2 раза, т.к. в json'е есть part-1 и part-2