var ppc = {
"cpu" : [
//intel cpu
{"name" : "Pentium-G4400", "price" : "240", "make" : "intel", "socket" : "1151"},
{"name" : "i3-6100", "price" : "520", "make" : "intel", "socket" : "1151"},
{"name" : "i3-3240", "price" : "614", "make" : "intel", "socket" : "1155"},
{"name" : "i3-6300", "price" : "745", "make" : "intel", "socket" : "1151"},
{"name" : "i5-4460", "price" : "850", "make" : "intel", "socket" : "1150"},
{"name" : "i5-6400", "price" : "850", "make" : "intel", "socket" : "1151"},
{"name" : "i5-4690", "price" : "950", "make" : "intel", "socket" : "1150"},
{"name" : "i5-6600K", "price" : "1100", "make" : "intel", "socket" : "1151"},
{"name" : "i7-4790", "price" : "1300", "make" : "intel", "socket" : "1150"},
{"name" : "i7-6700", "price" : "1500", "make" : "intel", "socket" : "1151"},
{"name" : "i7-6800K", "price" : "2250", "make" : "intel", "socket" : "2011"},
//AMD cpu
{"name" : "A8-7650K", "price" : "495", "make" : "amd", "socket" : "FM2"},
{"name" : "FX-8350", "price" : "800", "make" : "amd", "socket" : "AM3"},
{"name" : "FX-8370", "price" : "1010", "make" : "amd", "socket" : "AM3"}
]};
私のJSONオブジェクトを取得することはできません、あなたは何かを見ていますIコードで見ていない?iはちょっと、プロジェクトに取り組んでJavaScriptとイムにかなり新しいイム、イムの仕事にこのJSONを取得しようと、私はそれが仕事を得るカント右
function getRes() {
"use strict";
//use - 1 - gaming | 2 - video edit | 3 - music creator || 4 - photo edit | 5 - developer | 6 - simple
var cpub, gpub, mbb, ramb, memoryb, ssdb, fcpu, fgpu, fmb, fram, fmem, fssd, bud, cp, use, s, i, pc = JSON.parse(ppc);
cp = 1000;
bud = document.getElementById("budget");
//use = ((document.getElementById("use")||{}).value)||"";
//use = $("#use option:selected").html();
// if(use === 3 || use === 5 ||| use === 6)cpu = bud * 50/100;
// if (use === 1 || use === 2 || use === 4) {
console.log("step 1");
cpub = bud * 30/100;
gpub = bud * 30/100;
mbb = bud * 10/100;
ramb = bud * 10/100;
memoryb = bud * 10/100;
ssdb = bud * 10/100;
if (((document.getElementById("cpu-pref") || {}).value)||"" === 1) { // 1 = intel - 2 = amd
for (i in pc.cpu)
{
if (pc.cpu[i].price < cpub && pc.cpu[i].make === "intel" && (cpub - pc.cpu[i].price) < cp) {
cp = cpub - pc.cpu[i].price;
fcpu = pc.cpu[i].name;
s = i;
console.log("i =" + i);
console.log("fcpu =" + fcpu);
console.log("cp =" + cp);
console.log("cpu =" + cpub);
i = i + 1;
}
}
} else {
for(i in pc.cpu)
{
if (pc.cpu[i].price < cpub && pc.cpu[i].make === "amd" && (cpub - pc.cpu[i].price) < cp) {
cp = cpub - pc.cpu[i].price;
fcpu = pc.cpu[i].name;
s = i;
i = i + 1;
}
}
}
bud = bud - pc.cpu[s].price;
window.alert(fcpu);
// }
return 1;
}
このコードで達成したいことは?それは有効です –
これは今後の役に立つツールかもしれません:http://jsonlint.com/ –
純粋なJSONコメントで許可されていない点を除いて、JSONは有効です。しかしJavaScriptでは、それは有効なオブジェクトリテラルです。 – trincot