اذهب إلى المحتوى

السؤال

نشر

أحاول استخراج بيانات RoundNumber من ملف json الذي تم تمريره من الطلب في تطبيق Laravel الخاص بي بهذه الطريقة:

public function importResults(Request $request)
{
    $json = file_get_contents($request->file('results'));
    $decoded = json_decode($json);

    $roundNumber = $decoded->data->MatchingTables->RoundNumber;

    return $roundNumber;
    //return redirect('getPanel');
}

هذا ملف json

"MatchingTables": [{
            "RoundNumber": 1,
            "id_round": "JLLcrGFKokzyP147",
            "Team1": "xPn5sTmNcwZwA9XA",
            "Team2": null,
            "GameWins2": 0,
            "GameWins1": 0,
            "GameByes2": 0,
            "GameByes1": 0,
            "GameDraws": null,
            "Player1": null,
            "Player2": null,
            "Number": null,
            "Timestamp": 1676536691086,
            "MatchOrdinal": null,
            "_id": "5r14sENZ4LPyYp0Y"
        },
        {
            "Number": 3,
            "Timestamp": 1676536642961,
            "RoundNumber": 1,
            "Team1": "BtjUYtJKqB1DswuF",
            "Team2": "a0M2B44mfw6zgJPh",
            "Player1": "hFXO7VhvuB6dc9u4",
            "Player2": "yyCW3cTW3lbf3HP8",
            "GameWins1": null,
            "GameWins2": null,
            "GameByes1": null,
            "GameByes2": null,
            "GameDraws": null,
            "MatchOrdinal": 3,
            "id_round": "JLLcrGFKokzyP147",
            "_id": "7CgcJdgQJj3QpR7Z"
        },
        {
            "RoundNumber": 1,
            "id_round": "JLLcrGFKokzyP147",
            "Team1": "QtlYSLJ4RI9tUc09",
            "Team2": null,
            "GameWins2": null,
            "GameWins1": null,
            "GameByes2": null,
            "GameByes1": 1,
            "GameDraws": null,
            "Player1": null,
            "Player2": null,
            "Number": null,
            "Timestamp": 1676536688524,
            "MatchOrdinal": null,
            "_id": "PX8gLrgQ38RmOCUO"
        },
        {
            "Number": 1,
            "Timestamp": 1676536642961,
            "RoundNumber": 1,
            "Team1": "ZbBlDh1Uyt3e8Uvf",
            "Team2": "is01LkEzsWDtLTPv",
            "Player1": "62da1vAAK6z8bbxR",
            "Player2": "HPT4CJ8YM98WoqX3",
            "GameWins1": null,
            "GameWins2": null,
            "GameByes1": null,
            "GameByes2": null,
            "GameDraws": null,
            "MatchOrdinal": 1,
            "id_round": "JLLcrGFKokzyP147",
            "_id": "QWs3NXYofMS2dcKZ"
        },
        {
            "Number": null,
            "Timestamp": 1676536642961,
            "RoundNumber": 1,
            "Team1": "92Wlqmulw5YdtATz",
            "Player1": "iuv4J5dIlSo7LMfX",
            "Player2": null,
            "GameWins1": null,
            "GameWins2": null,
            "GameByes1": 1,
            "GameByes2": null,
            "GameDraws": null,
            "MatchOrdinal": 5,
            "id_round": "JLLcrGFKokzyP147",
            "_id": "eEEBX2dg5c8V5E1z"
        },
        {
            "Number": 2,
            "Timestamp": 1676536642961,
            "RoundNumber": 1,
            "Team1": "b4nenH6nO8mk2fr0",
            "Team2": "S65ushxkZAF53bZn",
            "Player1": "DaFDCZdVNWkizy6N",
            "Player2": "SFamW9qeVlVvoAq4",
            "GameWins1": null,
            "GameWins2": null,
            "GameByes1": null,
            "GameByes2": null,
            "GameDraws": null,
            "MatchOrdinal": 2,
            "id_round": "JLLcrGFKokzyP147",
            "_id": "oiXAZVsV5zevpPvi"
        }],

أريد استخراج خاصية "RoundNumber" من كل عنصر من عناصر المصفوفة. لقد حاولت أيضا بهذه الطرق:

$roundNumber = $decoded->data->MatchingTables["RoundNumber"];
$roundNumber = $decoded->data->MatchingTables[]->RoundNumber;

هل يمكنكم مساعدتي؟

Recommended Posts

  • 0
نشر

اهلا اخي الفاضل

دالة json_decode ترجع القيم مباشرة ولا تحتاج ان تنادي data

مباشرة: $decoded->MatchingTables

هذا اول خطأ

الخطأ الثاني ان MatchingTables هي عبارة عن مصفوفة

فيجب ان تختار index اولا من مصفوفة MatchingTables ثم تدخل إلى RoundNumber

مثلا $roundNumber = $decoded->MatchingTables[0]->RoundNumber;

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...